WithAttributes

Struct WithAttributes 

Source
pub struct WithAttributes<Attr, Value> {
    pub attr: Attr,
    pub separator: &'static str,
    pub value: Value,
}
Expand description

Adds attributes to ANY item.

The first tuple value must be a sequence. The second must be a writable value. This struct is typically constructed via CanHaveAttributes::with_attributes.

Rust attributes can be put in many places, so this enables you to add attributes to any writable item. For example, adding attributes to function parameters can be done like so:


let function_param = FunctionParam(Str("conditional_param"), Str("Fd")).with_attributes(
  SingularSeq(Cfg(Target::Os(Str("linux"))))
);
let string = InMemoryOutput::print_output(EmptyContext, &function_param);
assert_eq!("#[cfg(target_os = \"linux\")] conditional_param: Fd", string);

Fields§

§attr: Attr§separator: &'static str

The separator. Usually a space or a new line, depending on what the target value is

§value: Value

The value

Trait Implementations§

Source§

impl<Attr: Clone, Value: Clone> Clone for WithAttributes<Attr, Value>

Source§

fn clone(&self) -> WithAttributes<Attr, Value>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Attr: Debug, Value: Debug> Debug for WithAttributes<Attr, Value>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<O, Attr, Value> Writable<O> for WithAttributes<Attr, Value>
where O: Output, Attr: WritableSeq<O>, Value: Writable<O>,

Source§

async fn write_to(&self, output: &mut O) -> Result<(), O::Error>

Writes to the output. Returns the output’s error upon failure. Read more

Auto Trait Implementations§

§

impl<Attr, Value> Freeze for WithAttributes<Attr, Value>
where Attr: Freeze, Value: Freeze,

§

impl<Attr, Value> RefUnwindSafe for WithAttributes<Attr, Value>
where Attr: RefUnwindSafe, Value: RefUnwindSafe,

§

impl<Attr, Value> Send for WithAttributes<Attr, Value>
where Attr: Send, Value: Send,

§

impl<Attr, Value> Sync for WithAttributes<Attr, Value>
where Attr: Sync, Value: Sync,

§

impl<Attr, Value> Unpin for WithAttributes<Attr, Value>
where Attr: Unpin, Value: Unpin,

§

impl<Attr, Value> UnwindSafe for WithAttributes<Attr, Value>
where Attr: UnwindSafe, Value: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.