pub struct AttributeChain { /* private fields */ }Expand description
A parsed Rust attribute expression made from a path root and zero or more dot calls.
Accepted roots are:
- a path, such as
RangeValidation::<_>.
Implementations§
Source§impl AttributeChain
impl AttributeChain
Sourcepub fn parse_with_options(
input: ParseStream<'_>,
options: &ChainParseOptions,
) -> Result<Self>
pub fn parse_with_options( input: ParseStream<'_>, options: &ChainParseOptions, ) -> Result<Self>
Parse an AttributeChain from a ParseStream with custom options.
§Errors
Returns syn::Error when the token stream is not a supported path or
dot-call chain, completion probes are disabled for probe syntax, or the
configured completion marker cannot be emitted as a Rust identifier.
Sourcepub fn parse_tokens_with_options(
tokens: TokenStream,
options: &ChainParseOptions,
) -> Result<Self>
pub fn parse_tokens_with_options( tokens: TokenStream, options: &ChainParseOptions, ) -> Result<Self>
Parse an AttributeChain from tokens with custom options.
§Errors
Returns syn::Error for the same syntax and option failures as
Self::parse_with_options.
pub fn root(&self) -> &Path
Sourcepub fn root_path(&self) -> &Path
pub fn root_path(&self) -> &Path
Examples found in repository?
examples/derive_field_attrs.rs (line 68)
55fn expand_field_attrs(field: &Field) -> syn::Result<Vec<TokenStream>> {
56 let field_ident = field
57 .ident
58 .as_ref()
59 .expect("named_fields only returns named struct fields");
60 let mut expansions = Vec::new();
61
62 for attr in &field.attrs {
63 if !attr.path().is_ident("attribute_dsl") {
64 continue;
65 }
66
67 let chain = attr.parse_args::<AttributeChain>()?;
68 let root = substitute_infer_in_path(chain.root_path(), &field.ty);
69
70 let calls = chain.calls().iter().map(|call| {
71 let method = call.method();
72 let turbofish = call.turbofish();
73 let args = call.args();
74 quote! { .#method #turbofish (#(#args),*) }
75 });
76
77 let completion = chain
78 .completion_marker()
79 .map(|marker| quote! { .#marker })
80 .unwrap_or_default();
81
82 expansions.push(quote! {
83 let _ = #root::builder_for(stringify!(#field_ident)) #(#calls)* #completion;
84 });
85 }
86
87 Ok(expansions)
88}Sourcepub fn calls(&self) -> &[ChainCall]
pub fn calls(&self) -> &[ChainCall]
Examples found in repository?
examples/derive_field_attrs.rs (line 70)
55fn expand_field_attrs(field: &Field) -> syn::Result<Vec<TokenStream>> {
56 let field_ident = field
57 .ident
58 .as_ref()
59 .expect("named_fields only returns named struct fields");
60 let mut expansions = Vec::new();
61
62 for attr in &field.attrs {
63 if !attr.path().is_ident("attribute_dsl") {
64 continue;
65 }
66
67 let chain = attr.parse_args::<AttributeChain>()?;
68 let root = substitute_infer_in_path(chain.root_path(), &field.ty);
69
70 let calls = chain.calls().iter().map(|call| {
71 let method = call.method();
72 let turbofish = call.turbofish();
73 let args = call.args();
74 quote! { .#method #turbofish (#(#args),*) }
75 });
76
77 let completion = chain
78 .completion_marker()
79 .map(|marker| quote! { .#marker })
80 .unwrap_or_default();
81
82 expansions.push(quote! {
83 let _ = #root::builder_for(stringify!(#field_ident)) #(#calls)* #completion;
84 });
85 }
86
87 Ok(expansions)
88}pub fn completion(&self) -> &ChainCompletion
pub fn has_completion_probe(&self) -> bool
Sourcepub fn completion_marker(&self) -> Option<&Ident>
pub fn completion_marker(&self) -> Option<&Ident>
Examples found in repository?
examples/derive_field_attrs.rs (line 78)
55fn expand_field_attrs(field: &Field) -> syn::Result<Vec<TokenStream>> {
56 let field_ident = field
57 .ident
58 .as_ref()
59 .expect("named_fields only returns named struct fields");
60 let mut expansions = Vec::new();
61
62 for attr in &field.attrs {
63 if !attr.path().is_ident("attribute_dsl") {
64 continue;
65 }
66
67 let chain = attr.parse_args::<AttributeChain>()?;
68 let root = substitute_infer_in_path(chain.root_path(), &field.ty);
69
70 let calls = chain.calls().iter().map(|call| {
71 let method = call.method();
72 let turbofish = call.turbofish();
73 let args = call.args();
74 quote! { .#method #turbofish (#(#args),*) }
75 });
76
77 let completion = chain
78 .completion_marker()
79 .map(|marker| quote! { .#marker })
80 .unwrap_or_default();
81
82 expansions.push(quote! {
83 let _ = #root::builder_for(stringify!(#field_ident)) #(#calls)* #completion;
84 });
85 }
86
87 Ok(expansions)
88}pub fn span(&self) -> Span
Trait Implementations§
Source§impl Clone for AttributeChain
impl Clone for AttributeChain
Source§fn clone(&self) -> AttributeChain
fn clone(&self) -> AttributeChain
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for AttributeChain
impl Debug for AttributeChain
Source§impl Parse for AttributeChain
impl Parse for AttributeChain
fn parse(input: ParseStream<'_>) -> Result<Self>
Source§impl ToTokens for AttributeChain
impl ToTokens for AttributeChain
Source§fn to_tokens(&self, tokens: &mut TokenStream)
fn to_tokens(&self, tokens: &mut TokenStream)
Source§fn to_token_stream(&self) -> TokenStream
fn to_token_stream(&self) -> TokenStream
Source§fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
fn into_token_stream(self) -> TokenStreamwhere
Self: Sized,
Auto Trait Implementations§
impl !Send for AttributeChain
impl !Sync for AttributeChain
impl Freeze for AttributeChain
impl RefUnwindSafe for AttributeChain
impl Unpin for AttributeChain
impl UnsafeUnpin for AttributeChain
impl UnwindSafe for AttributeChain
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Spanned for Twhere
T: Spanned + ?Sized,
impl<T> Spanned for Twhere
T: Spanned + ?Sized,
Source§fn span(&self) -> Span
fn span(&self) -> Span
Returns a
Span covering the complete contents of this syntax tree
node, or Span::call_site() if this node is empty.