Struct add_ed::macros::Macro

source ·
#[non_exhaustive]
pub struct Macro { pub input: Cow<'static, str>, pub arguments: Option<usize>, }
Expand description

A struct representing a runnable macro

It is intended to add more/change the variables, but the constructors should produce instances with the same behaviour through any changes.

If the serde feature is enabled, serialization will produce the most backwards compatible representation while still ensuring the same behaviour. Deserialization should produce identically behaving macros when valid for the version of add-ed being used, if newer features are used in the macro than the deserializing version of add-ed has access to an unknown field error will be raised.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§input: Cow<'static, str>

Input to simulate

Should be a string of newline separated commands. Execution is equivalent to if this input was given on STDIN while the editor is running.

§arguments: Option<usize>

The number of arguments the macro accepts

None means there is no specific number, disabling validation of correct nr of given arguments before execution. Some(0) means the macro expects no arguments, as such no argument substitution will be performed.

Implementations§

source§

impl Macro

source

pub fn new<T: Into<Cow<'static, str>>>(input: T, arguments: usize) -> Self

Construct a macro

Creates a macro with the given text as command input and the given nr of allowed arguments. If 0 arguments expected no argument substitution will be performed for the macro.

source

pub fn without_arg_validation<T: Into<Cow<'static, str>>>(input: T) -> Self

Construct a macro that takes any number of commands

Creates a macro with the given text as command input and disables validation of nr of arguments to the macro. This is intended for macros using the “all arguments” substitutor instead of numbered argument substitutors.

Trait Implementations§

source§

impl Debug for Macro

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Macro

§

impl Send for Macro

§

impl Sync for Macro

§

impl Unpin for Macro

§

impl UnwindSafe for Macro

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> AsAny for T
where T: Any,

source§

fn as_any(&self) -> &(dyn Any + 'static)

source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

source§

fn type_name(&self) -> &'static str

Gets the type name of self
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> Downcast for T
where T: AsAny + ?Sized,

source§

fn is<T>(&self) -> bool
where T: AsAny,

Returns true if the boxed type is the same as T. Read more
source§

fn downcast_ref<T>(&self) -> Option<&T>
where T: AsAny,

Forward to the method defined on the type Any.
source§

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: AsAny,

Forward to the method defined on the type Any.
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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.