Struct EditorBuilder

Source
pub struct EditorBuilder<'a> { /* private fields */ }
Expand description

A builder for a Command that will open the user’s configured editor. For simple cases you probably can just use EditorBuilder::edit_file. See crate-level documentation for more details and examples.

Implementations§

Source§

impl<'a> EditorBuilder<'a>

Source

pub fn new() -> Self

Create a new editor command with no sources. You probably want to call environment on the returned value.

Source

pub fn edit_file(path: impl AsRef<Path>) -> Result<Command, EditorBuilderError>

Shorthand for opening a file with the command set in VISUAL/EDITOR.

EditorBuilder::edit_file("file.yml")

is equivalent to:

EditorBuilder::new().environment().path(path).build()
Source

pub fn source(self, source: Option<impl Into<Cow<'a, str>>>) -> Self

Add a static string as a source for the command. This is useful for static defaults, or external sources such as a configuration file. This accepts an Option so you can easily build a chain of sources that may or may not be defined.

Source

pub fn environment(self) -> Self

Add the VISUAL and EDITOR environment variables, in that order. The variables will be evaluated immediately, not during build.

Source

pub fn path(self, path: impl Into<Cow<'a, Path>>) -> Self

Define the path to be passed as the final argument.

§Multiple Calls

Subsequent calls to this on the same instance will append to the list of paths. The paths will all be included in the final command, in the order this method was called.

Source

pub fn build(self) -> Result<Command, EditorBuilderError>

Search all configured sources (in their order of definition), and parse the first one that’s populated as a shell command. Then use that to build an executable Command.

Trait Implementations§

Source§

impl<'a> Clone for EditorBuilder<'a>

Source§

fn clone(&self) -> EditorBuilder<'a>

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<'a> Debug for EditorBuilder<'a>

Source§

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

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

impl<'a> Default for EditorBuilder<'a>

Source§

fn default() -> EditorBuilder<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for EditorBuilder<'a>

§

impl<'a> RefUnwindSafe for EditorBuilder<'a>

§

impl<'a> Send for EditorBuilder<'a>

§

impl<'a> Sync for EditorBuilder<'a>

§

impl<'a> Unpin for EditorBuilder<'a>

§

impl<'a> UnwindSafe for EditorBuilder<'a>

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.