1 use hir::{AsAssocItem, HasVisibility, ModuleDef, Visibility};
2 use ide_db::assists::{AssistId, AssistKind};
3 use itertools::Itertools;
4 use stdx::{format_to, to_lower_snake_case};
6 algo::skip_whitespace_token,
7 ast::{self, edit::IndentLevel, HasDocComments, HasName},
8 match_ast, AstNode, AstToken,
11 use crate::assist_context::{AssistContext, Assists};
13 // Assist: generate_documentation_template
15 // Adds a documentation template above a function definition / declaration.
20 // pub unsafe fn set_len$0(&mut self, len: usize) -> Result<(), std::io::Error> {
29 // /// Sets the length of this [`S`].
33 // /// This function will return an error if .
38 // pub unsafe fn set_len(&mut self, len: usize) -> Result<(), std::io::Error> {
43 pub(crate) fn generate_documentation_template(
45 ctx: &AssistContext<'_>,
47 let name = ctx.find_node_at_offset::<ast::Name>()?;
48 let ast_func = name.syntax().parent().and_then(ast::Fn::cast)?;
49 if is_in_trait_impl(&ast_func, ctx) || ast_func.doc_comments().next().is_some() {
53 let parent_syntax = ast_func.syntax();
54 let text_range = parent_syntax.text_range();
55 let indent_level = IndentLevel::from_node(parent_syntax);
58 AssistId("generate_documentation_template", AssistKind::Generate),
59 "Generate a documentation template",
62 // Introduction / short function description before the sections
63 let mut doc_lines = vec![introduction_builder(&ast_func, ctx).unwrap_or(".".into())];
64 // Then come the sections
65 for section_builder in [panics_builder, errors_builder, safety_builder] {
66 if let Some(mut lines) = section_builder(&ast_func) {
67 doc_lines.push("".into());
68 doc_lines.append(&mut lines);
71 builder.insert(text_range.start(), documentation_from_lines(doc_lines, indent_level));
76 // Assist: generate_doc_example
78 // Generates a rustdoc example when editing an item's documentation.
81 // /// Adds two numbers.$0
82 // pub fn add(a: i32, b: i32) -> i32 { a + b }
86 // /// Adds two numbers.
93 // /// assert_eq!(add(a, b), );
95 // pub fn add(a: i32, b: i32) -> i32 { a + b }
97 pub(crate) fn generate_doc_example(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
98 let tok: ast::Comment = ctx.find_token_at_offset()?;
99 let node = tok.syntax().parent()?;
101 ast::AnyHasDocComments::cast(node.clone())?.doc_comments().last()?.syntax().clone();
102 let next_token = skip_whitespace_token(last_doc_token.next_token()?, syntax::Direction::Next)?;
104 let example = match_ast! {
106 ast::Fn(it) => make_example_for_fn(&it, ctx)?,
111 let mut lines = string_vec_from(&["", "# Examples", "", "```"]);
112 lines.extend(example.lines().map(String::from));
113 lines.push("```".into());
114 let indent_level = IndentLevel::from_node(&node);
117 AssistId("generate_doc_example", AssistKind::Generate),
118 "Generate a documentation example",
122 next_token.text_range().start(),
123 documentation_from_lines(lines, indent_level),
129 fn make_example_for_fn(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<String> {
130 if !is_public(ast_func, ctx)? {
131 // Doctests for private items can't actually name the item, so they're pretty useless.
135 if is_in_trait_def(ast_func, ctx) {
136 // This is not yet implemented.
140 let mut example = String::new();
142 let use_path = build_path(ast_func, ctx)?;
143 let is_unsafe = ast_func.unsafe_token().is_some();
144 let param_list = ast_func.param_list()?;
145 let ref_mut_params = ref_mut_params(¶m_list);
146 let self_name = self_name(ast_func);
148 format_to!(example, "use {use_path};\n\n");
149 if let Some(self_name) = &self_name {
150 if let Some(mut_) = is_ref_mut_self(ast_func) {
151 let mut_ = if mut_ == true { "mut " } else { "" };
152 format_to!(example, "let {mut_}{self_name} = ;\n");
155 for param_name in &ref_mut_params {
156 format_to!(example, "let mut {param_name} = ;\n");
158 // Call the function, check result
159 let function_call = function_call(ast_func, ¶m_list, self_name.as_deref(), is_unsafe)?;
160 if returns_a_value(ast_func, ctx) {
161 if count_parameters(¶m_list) < 3 {
162 format_to!(example, "assert_eq!({function_call}, );\n");
164 format_to!(example, "let result = {function_call};\n");
165 example.push_str("assert_eq!(result, );\n");
168 format_to!(example, "{function_call};\n");
170 // Check the mutated values
171 if let Some(self_name) = &self_name {
172 if is_ref_mut_self(ast_func) == Some(true) {
173 format_to!(example, "assert_eq!({self_name}, );");
176 for param_name in &ref_mut_params {
177 format_to!(example, "assert_eq!({param_name}, );");
183 fn introduction_builder(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<String> {
184 let hir_func = ctx.sema.to_def(ast_func)?;
185 let container = hir_func.as_assoc_item(ctx.db())?.container(ctx.db());
186 if let hir::AssocItemContainer::Impl(imp) = container {
187 let ret_ty = hir_func.ret_type(ctx.db());
188 let self_ty = imp.self_ty(ctx.db());
189 let name = ast_func.name()?.to_string();
190 let linkable_self_ty = self_type_without_lifetimes(ast_func);
191 let linkable_self_ty = linkable_self_ty.as_deref();
193 let intro_for_new = || {
194 let is_new = name == "new";
195 if is_new && ret_ty == self_ty {
196 let self_ty = linkable_self_ty?;
197 Some(format!("Creates a new [`{self_ty}`]."))
203 let intro_for_getter = || match (
204 hir_func.self_param(ctx.sema.db),
205 &*hir_func.params_without_self(ctx.sema.db),
207 (Some(self_param), []) if self_param.access(ctx.sema.db) != hir::Access::Owned => {
208 if name.starts_with("as_") || name.starts_with("to_") || name == "get" {
211 let mut what = name.trim_end_matches("_mut").replace('_', " ");
213 what = "length".into()
215 let reference = if ret_ty.is_mutable_reference() {
216 " a mutable reference to"
217 } else if ret_ty.is_reference() {
223 let self_ty = linkable_self_ty?;
224 Some(format!("Returns{reference} the {what} of this [`{self_ty}`]."))
229 let intro_for_setter = || {
230 if !name.starts_with("set_") {
234 let mut what = name.trim_start_matches("set_").replace('_', " ");
236 what = "length".into()
239 let self_ty = linkable_self_ty?;
240 Some(format!("Sets the {what} of this [`{self_ty}`]."))
243 if let Some(intro) = intro_for_new() {
246 if let Some(intro) = intro_for_getter() {
249 if let Some(intro) = intro_for_setter() {
256 /// Builds an optional `# Panics` section
257 fn panics_builder(ast_func: &ast::Fn) -> Option<Vec<String>> {
258 match can_panic(ast_func) {
259 Some(true) => Some(string_vec_from(&["# Panics", "", "Panics if ."])),
264 /// Builds an optional `# Errors` section
265 fn errors_builder(ast_func: &ast::Fn) -> Option<Vec<String>> {
266 match return_type(ast_func)?.to_string().contains("Result") {
267 true => Some(string_vec_from(&["# Errors", "", "This function will return an error if ."])),
272 /// Builds an optional `# Safety` section
273 fn safety_builder(ast_func: &ast::Fn) -> Option<Vec<String>> {
274 let is_unsafe = ast_func.unsafe_token().is_some();
276 true => Some(string_vec_from(&["# Safety", "", "."])),
281 /// Checks if the function is public / exported
282 fn is_public(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<bool> {
283 let hir_func = ctx.sema.to_def(ast_func)?;
285 hir_func.visibility(ctx.db()) == Visibility::Public
286 && all_parent_mods_public(&hir_func, ctx),
290 /// Checks that all parent modules of the function are public / exported
291 fn all_parent_mods_public(hir_func: &hir::Function, ctx: &AssistContext<'_>) -> bool {
292 let mut module = hir_func.module(ctx.db());
294 if let Some(parent) = module.parent(ctx.db()) {
295 match ModuleDef::from(module).visibility(ctx.db()) {
296 Visibility::Public => module = parent,
305 /// Returns the name of the current crate
306 fn crate_name(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<String> {
307 let krate = ctx.sema.scope(ast_func.syntax())?.krate();
308 Some(krate.display_name(ctx.db())?.to_string())
311 /// `None` if function without a body; some bool to guess if function can panic
312 fn can_panic(ast_func: &ast::Fn) -> Option<bool> {
313 let body = ast_func.body()?.to_string();
314 let can_panic = body.contains("panic!(")
315 // FIXME it would be better to not match `debug_assert*!` macro invocations
316 || body.contains("assert!(")
317 || body.contains(".unwrap()")
318 || body.contains(".expect(");
322 /// Helper function to get the name that should be given to `self` arguments
323 fn self_name(ast_func: &ast::Fn) -> Option<String> {
324 self_partial_type(ast_func).map(|name| to_lower_snake_case(&name))
327 /// Heper function to get the name of the type of `self`
328 fn self_type(ast_func: &ast::Fn) -> Option<ast::Type> {
329 ast_func.syntax().ancestors().find_map(ast::Impl::cast).and_then(|i| i.self_ty())
332 /// Output the real name of `Self` like `MyType<T>`, without the lifetimes.
333 fn self_type_without_lifetimes(ast_func: &ast::Fn) -> Option<String> {
334 let path_segment = match self_type(ast_func)? {
335 ast::Type::PathType(path_type) => path_type.path()?.segment()?,
338 let mut name = path_segment.name_ref()?.to_string();
339 let generics = path_segment.generic_arg_list().into_iter().flat_map(|list| {
341 .filter(|generic| matches!(generic, ast::GenericArg::TypeArg(_)))
342 .map(|generic| generic.to_string())
344 let generics: String = generics.format(", ").to_string();
345 if !generics.is_empty() {
347 name.push_str(&generics);
353 /// Heper function to get the name of the type of `self` without generic arguments
354 fn self_partial_type(ast_func: &ast::Fn) -> Option<String> {
355 let mut self_type = self_type(ast_func)?.to_string();
356 if let Some(idx) = self_type.find(|c| ['<', ' '].contains(&c)) {
357 self_type.truncate(idx);
362 /// Helper function to determine if the function is in a trait implementation
363 fn is_in_trait_impl(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> bool {
366 .and_then(|hir_func| hir_func.as_assoc_item(ctx.db()))
367 .and_then(|assoc_item| assoc_item.containing_trait_impl(ctx.db()))
371 /// Helper function to determine if the function definition is in a trait definition
372 fn is_in_trait_def(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> bool {
375 .and_then(|hir_func| hir_func.as_assoc_item(ctx.db()))
376 .and_then(|assoc_item| assoc_item.containing_trait(ctx.db()))
380 /// Returns `None` if no `self` at all, `Some(true)` if there is `&mut self` else `Some(false)`
381 fn is_ref_mut_self(ast_func: &ast::Fn) -> Option<bool> {
382 let self_param = ast_func.param_list()?.self_param()?;
383 Some(self_param.mut_token().is_some() && self_param.amp_token().is_some())
386 /// Helper function to determine if a parameter is `&mut`
387 fn is_a_ref_mut_param(param: &ast::Param) -> bool {
389 Some(ast::Type::RefType(param_ref)) => param_ref.mut_token().is_some(),
394 /// Helper function to build the list of `&mut` parameters
395 fn ref_mut_params(param_list: &ast::ParamList) -> Vec<String> {
398 .filter_map(|param| match is_a_ref_mut_param(¶m) {
399 // Maybe better filter the param name (to do this maybe extract a function from
400 // `arguments_from_params`?) in case of a `mut a: &mut T`. Anyway managing most (not
401 // all) cases might be enough, the goal is just to produce a template.
402 true => Some(param.pat()?.to_string()),
408 /// Helper function to build the comma-separated list of arguments of the function
409 fn arguments_from_params(param_list: &ast::ParamList) -> String {
410 let args_iter = param_list.params().map(|param| match param.pat() {
411 // To avoid `mut` in the function call (which would be a nonsense), `Pat` should not be
412 // written as is so its variants must be managed independently. Other variants (for
413 // instance `TuplePat`) could be managed later.
414 Some(ast::Pat::IdentPat(ident_pat)) => match ident_pat.name() {
415 Some(name) => match is_a_ref_mut_param(¶m) {
416 true => format!("&mut {name}"),
417 false => name.to_string(),
419 None => "_".to_string(),
421 _ => "_".to_string(),
423 args_iter.format(", ").to_string()
426 /// Helper function to build a function call. `None` if expected `self_name` was not provided
429 param_list: &ast::ParamList,
430 self_name: Option<&str>,
432 ) -> Option<String> {
433 let name = ast_func.name()?;
434 let arguments = arguments_from_params(param_list);
435 let function_call = if param_list.self_param().is_some() {
436 let self_ = self_name?;
437 format!("{self_}.{name}({arguments})")
438 } else if let Some(implementation) = self_partial_type(ast_func) {
439 format!("{implementation}::{name}({arguments})")
441 format!("{name}({arguments})")
444 true => Some(format!("unsafe {{ {function_call} }}")),
445 false => Some(function_call),
449 /// Helper function to count the parameters including `self`
450 fn count_parameters(param_list: &ast::ParamList) -> usize {
451 param_list.params().count() + if param_list.self_param().is_some() { 1 } else { 0 }
454 /// Helper function to transform lines of documentation into a Rust code documentation
455 fn documentation_from_lines(doc_lines: Vec<String>, indent_level: IndentLevel) -> String {
456 let mut result = String::new();
457 for doc_line in doc_lines {
458 result.push_str("///");
459 if !doc_line.is_empty() {
461 result.push_str(&doc_line);
464 result.push_str(&indent_level.to_string());
469 /// Helper function to transform an array of borrowed strings to an owned `Vec<String>`
470 fn string_vec_from(string_array: &[&str]) -> Vec<String> {
471 string_array.iter().map(|&s| s.to_owned()).collect()
474 /// Helper function to build the path of the module in the which is the node
475 fn build_path(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> Option<String> {
476 let crate_name = crate_name(ast_func, ctx)?;
477 let leaf = self_partial_type(ast_func)
478 .or_else(|| ast_func.name().map(|n| n.to_string()))
479 .unwrap_or_else(|| "*".into());
480 let module_def: ModuleDef = ctx.sema.to_def(ast_func)?.module(ctx.db()).into();
481 match module_def.canonical_path(ctx.db()) {
482 Some(path) => Some(format!("{crate_name}::{path}::{leaf}")),
483 None => Some(format!("{crate_name}::{leaf}")),
487 /// Helper function to get the return type of a function
488 fn return_type(ast_func: &ast::Fn) -> Option<ast::Type> {
489 ast_func.ret_type()?.ty()
492 /// Helper function to determine if the function returns some data
493 fn returns_a_value(ast_func: &ast::Fn, ctx: &AssistContext<'_>) -> bool {
496 .map(|hir_func| hir_func.ret_type(ctx.db()))
497 .map(|ret_ty| !ret_ty.is_unit() && !ret_ty.is_never())
503 use crate::tests::{check_assist, check_assist_not_applicable};
508 fn not_applicable_on_function_calls() {
509 check_assist_not_applicable(
510 generate_documentation_template,
513 fn calls_hello_world() {
521 fn not_applicable_in_trait_impl() {
522 check_assist_not_applicable(
523 generate_documentation_template,
527 impl MyTrait for MyStruct {
535 fn not_applicable_if_function_already_documented() {
536 check_assist_not_applicable(
537 generate_documentation_template,
539 /// Some documentation here
540 pub fn $0documented_function() {}
546 fn supports_noop_function() {
548 generate_documentation_template,
560 fn is_applicable_if_function_is_private() {
562 generate_documentation_template,
574 fn no_doc_example_for_private_fn() {
575 check_assist_not_applicable(
576 generate_doc_example,
585 fn supports_a_parameter() {
587 generate_doc_example,
590 pub fn noop_with_param(_a: i32) {}
598 /// use test::noop_with_param;
600 /// noop_with_param(_a);
602 pub fn noop_with_param(_a: i32) {}
608 fn detects_unsafe_function() {
610 generate_documentation_template,
612 pub unsafe fn no$0op_unsafe() {}
620 pub unsafe fn noop_unsafe() {}
624 generate_doc_example,
631 pub unsafe fn noop_unsafe() {}
643 /// use test::noop_unsafe;
645 /// unsafe { noop_unsafe() };
647 pub unsafe fn noop_unsafe() {}
653 fn guesses_panic_macro_can_panic() {
655 generate_documentation_template,
657 pub fn panic$0s_if(a: bool) {
669 pub fn panics_if(a: bool) {
679 fn guesses_assert_macro_can_panic() {
681 generate_documentation_template,
683 pub fn $0panics_if_not(a: bool) {
693 pub fn panics_if_not(a: bool) {
701 fn guesses_unwrap_can_panic() {
703 generate_documentation_template,
705 pub fn $0panics_if_none(a: Option<()>) {
715 pub fn panics_if_none(a: Option<()>) {
723 fn guesses_expect_can_panic() {
725 generate_documentation_template,
727 pub fn $0panics_if_none2(a: Option<()>) {
737 pub fn panics_if_none2(a: Option<()>) {
745 fn checks_output_in_example() {
747 generate_doc_example,
750 pub fn returns_a_value$0() -> i32 {
760 /// use test::returns_a_value;
762 /// assert_eq!(returns_a_value(), );
764 pub fn returns_a_value() -> i32 {
772 fn detects_result_output() {
774 generate_documentation_template,
776 pub fn returns_a_result$0() -> Result<i32, std::io::Error> {
785 /// This function will return an error if .
786 pub fn returns_a_result() -> Result<i32, std::io::Error> {
794 fn checks_ref_mut_in_example() {
796 generate_doc_example,
799 pub fn modifies_a_value$0(a: &mut i32) {
809 /// use test::modifies_a_value;
812 /// modifies_a_value(&mut a);
815 pub fn modifies_a_value(a: &mut i32) {
823 fn stores_result_if_at_least_3_params() {
825 generate_doc_example,
828 pub fn sum3$0(a: i32, b: i32, c: i32) -> i32 {
840 /// let result = sum3(a, b, c);
841 /// assert_eq!(result, );
843 pub fn sum3(a: i32, b: i32, c: i32) -> i32 {
851 fn supports_fn_in_mods() {
853 generate_doc_example,
870 /// use test::a::b::noop;
882 fn supports_fn_in_impl() {
884 generate_doc_example,
900 /// use test::MyStruct;
902 /// MyStruct::noop();
911 fn supports_unsafe_fn_in_trait() {
913 generate_documentation_template,
916 unsafe fn unsafe_funct$0ion_trait();
926 unsafe fn unsafe_function_trait();
933 fn supports_fn_in_trait_with_default_panicking() {
935 generate_documentation_template,
938 fn function_trait_with_$0default_panicking() {
950 fn function_trait_with_default_panicking() {
959 fn supports_fn_in_trait_returning_result() {
961 generate_documentation_template,
964 fn function_tr$0ait_returning_result() -> Result<(), std::io::Error>;
973 /// This function will return an error if .
974 fn function_trait_returning_result() -> Result<(), std::io::Error>;
983 generate_documentation_template,
985 pub struct String(u8);
987 pub fn new$0(x: u8) -> String {
993 pub struct String(u8);
995 /// Creates a new [`String`].
996 pub fn new(x: u8) -> String {
1003 generate_documentation_template,
1005 #[derive(Debug, PartialEq)]
1006 pub struct MyGenericStruct<T> {
1009 impl<T> MyGenericStruct<T> {
1010 pub fn new$0(x: T) -> MyGenericStruct<T> {
1011 MyGenericStruct { x }
1016 #[derive(Debug, PartialEq)]
1017 pub struct MyGenericStruct<T> {
1020 impl<T> MyGenericStruct<T> {
1021 /// Creates a new [`MyGenericStruct<T>`].
1022 pub fn new(x: T) -> MyGenericStruct<T> {
1023 MyGenericStruct { x }
1031 fn removes_one_lifetime_from_description() {
1033 generate_documentation_template,
1035 #[derive(Debug, PartialEq)]
1036 pub struct MyGenericStruct<'a, T> {
1039 impl<'a, T> MyGenericStruct<'a, T> {
1040 pub fn new$0(x: &'a T) -> Self {
1041 MyGenericStruct { x }
1046 #[derive(Debug, PartialEq)]
1047 pub struct MyGenericStruct<'a, T> {
1050 impl<'a, T> MyGenericStruct<'a, T> {
1051 /// Creates a new [`MyGenericStruct<T>`].
1052 pub fn new(x: &'a T) -> Self {
1053 MyGenericStruct { x }
1061 fn removes_all_lifetimes_from_description() {
1063 generate_documentation_template,
1065 #[derive(Debug, PartialEq)]
1066 pub struct MyGenericStruct<'a, 'b, T> {
1070 impl<'a, 'b, T> MyGenericStruct<'a, 'b, T> {
1071 pub fn new$0(x: &'a T, y: &'b T) -> Self {
1072 MyGenericStruct { x, y }
1077 #[derive(Debug, PartialEq)]
1078 pub struct MyGenericStruct<'a, 'b, T> {
1082 impl<'a, 'b, T> MyGenericStruct<'a, 'b, T> {
1083 /// Creates a new [`MyGenericStruct<T>`].
1084 pub fn new(x: &'a T, y: &'b T) -> Self {
1085 MyGenericStruct { x, y }
1093 fn removes_all_lifetimes_and_brackets_from_description() {
1095 generate_documentation_template,
1097 #[derive(Debug, PartialEq)]
1098 pub struct MyGenericStruct<'a, 'b> {
1102 impl<'a, 'b> MyGenericStruct<'a, 'b> {
1103 pub fn new$0(x: &'a usize, y: &'b usize) -> Self {
1104 MyGenericStruct { x, y }
1109 #[derive(Debug, PartialEq)]
1110 pub struct MyGenericStruct<'a, 'b> {
1114 impl<'a, 'b> MyGenericStruct<'a, 'b> {
1115 /// Creates a new [`MyGenericStruct`].
1116 pub fn new(x: &'a usize, y: &'b usize) -> Self {
1117 MyGenericStruct { x, y }
1125 fn detects_new_with_self() {
1127 generate_documentation_template,
1129 #[derive(Debug, PartialEq)]
1130 pub struct MyGenericStruct2<T> {
1133 impl<T> MyGenericStruct2<T> {
1134 pub fn new$0(x: T) -> Self {
1135 MyGenericStruct2 { x }
1140 #[derive(Debug, PartialEq)]
1141 pub struct MyGenericStruct2<T> {
1144 impl<T> MyGenericStruct2<T> {
1145 /// Creates a new [`MyGenericStruct2<T>`].
1146 pub fn new(x: T) -> Self {
1147 MyGenericStruct2 { x }
1155 fn supports_method_call() {
1157 generate_doc_example,
1159 impl<T> MyGenericStruct<T> {
1161 pub fn consume(self) {}
1165 impl<T> MyGenericStruct<T> {
1171 /// use test::MyGenericStruct;
1173 /// let my_generic_struct = ;
1174 /// my_generic_struct.consume();
1176 pub fn consume(self) {}
1183 fn checks_modified_self_param() {
1185 generate_doc_example,
1187 impl<T> MyGenericStruct<T> {
1189 pub fn modify(&mut self, new_value: T) {
1195 impl<T> MyGenericStruct<T> {
1201 /// use test::MyGenericStruct;
1203 /// let mut my_generic_struct = ;
1204 /// my_generic_struct.modify(new_value);
1205 /// assert_eq!(my_generic_struct, );
1207 pub fn modify(&mut self, new_value: T) {
1216 fn generates_intro_for_getters() {
1218 generate_documentation_template,
1222 pub fn speed$0(&self) -> f32 { 0.0 }
1228 /// Returns the speed of this [`S`].
1229 pub fn speed(&self) -> f32 { 0.0 }
1234 generate_documentation_template,
1238 pub fn data$0(&self) -> &[u8] { &[] }
1244 /// Returns a reference to the data of this [`S`].
1245 pub fn data(&self) -> &[u8] { &[] }
1250 generate_documentation_template,
1254 pub fn data$0(&mut self) -> &mut [u8] { &mut [] }
1260 /// Returns a mutable reference to the data of this [`S`].
1261 pub fn data(&mut self) -> &mut [u8] { &mut [] }
1266 generate_documentation_template,
1270 pub fn data_mut$0(&mut self) -> &mut [u8] { &mut [] }
1276 /// Returns a mutable reference to the data of this [`S`].
1277 pub fn data_mut(&mut self) -> &mut [u8] { &mut [] }
1284 fn no_getter_intro_for_prefixed_methods() {
1286 generate_documentation_template,
1290 pub fn as_bytes$0(&self) -> &[u8] { &[] }
1297 pub fn as_bytes(&self) -> &[u8] { &[] }
1304 fn generates_intro_for_setters() {
1306 generate_documentation_template,
1310 pub fn set_data$0(&mut self, data: Vec<u8>) {}
1316 /// Sets the data of this [`S`].
1317 pub fn set_data(&mut self, data: Vec<u8>) {}
1322 generate_documentation_template,
1326 pub fn set_domain_name$0(&mut self, name: String) {}
1332 /// Sets the domain name of this [`S`].
1333 pub fn set_domain_name(&mut self, name: String) {}