Struct darling::util::IdentList
[−]
pub struct IdentList(_);
A list of syn::Ident
instances. This type is used to extract a list of words from an
attribute.
Usage
An IdentList
field on a struct implementing FromMetaItem
will turn #[builder(derive(Debug, Clone))]
into:
StructOptions { derive: IdentList(vec![syn::Ident::new("Debug"), syn::Ident::new("Clone")]) }
Methods
impl IdentList
fn new<T>(vals: Vec<T>) -> IdentList where
T: Into<Ident>,
T: Into<Ident>,
Create a new list.
fn as_strs(&'a self) -> Vec<&'a str>
Creates a view of the contained identifiers as &str
s.
Methods from Deref<Target = Vec<Ident>>
fn capacity(&self) -> usize
1.0.0
Returns the number of elements the vector can hold without reallocating.
Examples
let vec: Vec<i32> = Vec::with_capacity(10); assert_eq!(vec.capacity(), 10);
fn into_boxed_slice(self) -> Box<[T]>
1.0.0
Converts the vector into Box<[T]>
.
Note that this will drop any excess capacity. Calling this and
converting back to a vector with into_vec
is equivalent to calling
shrink_to_fit
.
Examples
let v = vec![1, 2, 3]; let slice = v.into_boxed_slice();
Any excess capacity is removed:
let mut vec = Vec::with_capacity(10); vec.extend([1, 2, 3].iter().cloned()); assert_eq!(vec.capacity(), 10); let slice = vec.into_boxed_slice(); assert_eq!(slice.into_vec().capacity(), 3);
fn as_slice(&self) -> &[T]
1.7.0
Extracts a slice containing the entire vector.
Equivalent to &s[..]
.
Examples
use std::io::{self, Write}; let buffer = vec![1, 2, 3, 5, 8]; io::sink().write(buffer.as_slice()).unwrap();
fn len(&self) -> usize
1.0.0
Returns the number of elements in the vector, also referred to as its 'length'.
Examples
let a = vec![1, 2, 3]; assert_eq!(a.len(), 3);
fn is_empty(&self) -> bool
1.0.0
Returns true
if the vector contains no elements.
Examples
let mut v = Vec::new(); assert!(v.is_empty()); v.push(1); assert!(!v.is_empty());
Trait Implementations
impl Debug for IdentList
impl Default for IdentList
impl From<Vec<Ident>> for IdentList
impl Deref for IdentList
impl FromMetaItem for IdentList
fn from_list(v: &[NestedMetaItem]) -> Result<IdentList, Error>
Create an instance from a list of nested meta items.
fn from_nested_meta_item(item: &NestedMetaItem) -> Result<Self, Error>
fn from_meta_item(item: &MetaItem) -> Result<Self, Error>
Create an instance from a syn::MetaItem
by dispatching to the format-appropriate trait function. This generally should not be overridden by implementers. Read more
fn from_word() -> Result<Self, Error>
Create an instance from the presence of the word in the attribute with no additional options specified. Read more
fn from_value(value: &Lit) -> Result<Self, Error>
Create an instance from a literal value of either foo = "bar"
or foo("bar")
. This dispatches to the appropriate method based on the type of literal encountered, and generally should not be overridden by implementers. Read more
fn from_char(value: char) -> Result<Self, Error>
Create an instance from a char literal in a value position.
fn from_string(value: &str) -> Result<Self, Error>
Create an instance from a string literal in a value position.
fn from_bool(value: bool) -> Result<Self, Error>
Create an instance from a bool literal in a value position.