Trait conciliator::edit::Edit

source ·
pub trait Edit {
    type T;
    type Err: Error + From<IoError>;

    const EXTENSION: &'static str;

    // Required methods
    fn write<W: Write>(&self, w: &mut W) -> Result<(), Self::Err>;
    fn read<C>(&self, content: String, con: &C) -> Option<Self::T>
       where C: Conciliator + ?Sized;
}
Expand description

Types that can be edited

See the module level docs for more information.

Required Associated Types§

source

type T

Type returned from editing

This could be different from the type that is “passed in” to the implementor.

source

type Err: Error + From<IoError>

Error for Edited::Err

Even though EditError (which is what is used for TomlEditor) is already generic, implementations are not required to use it. For example, the impl Edit for &str doesn’t need to do any serializing and can only encounter IO errors - this is why its Edit::Err is simply std::io::Error.

Note that this does not need to encompass errors encountered during the read method: any parsing errors are immediately reported for the user to fix.

Required Associated Constants§

source

const EXTENSION: &'static str

Extension of the temporary file

This gives the text editor a chance to apply the correct syntax highlighting automatically.

Don’t add a leading ., e.g. just "toml" or "txt".

Required Methods§

source

fn write<W: Write>(&self, w: &mut W) -> Result<(), Self::Err>

Write content into the file to be edited

This usually involves serializing the type.

This method is called only once to write to the new, empty, temporary file, but future versions may give users the ability to “reset” the file. As such it should be implemented assuming it may be called arbitrarily often.

source

fn read<C>(&self, content: String, con: &C) -> Option<Self::T>
where C: Conciliator + ?Sized,

Read (and parse) the edited file, immediately reporting any errors encountered

Because it would be inconvenient to add yet another Err type and return a Result to be reported in Claw::edit, errors this function encounters are to be reported immediately, using the reference to the Claw that invoked the edit (though it may be a different Conciliator implementor in future). This is because the user will be offered the option to amend the file if read returns None. The user will keep being offered this option until they either submit a file that can be parsed or they decide to abort the edit procedure.
This means that any errors this function is expected to encounter should be ones the user can recover from and if irrecoverable errors exist they should be rare and clearly communicated.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'s> Edit for &'s str

Edit a plain string, no serialization or parsing

source§

const EXTENSION: &'static str = "txt"

§

type T = String

§

type Err = Error

source§

fn write<W: Write>(&self, w: &mut W) -> Result<(), IoError>

source§

fn read<C>(&self, content: String, _con: &C) -> Option<Self::T>
where C: Conciliator + ?Sized,

Implementors§

source§

impl<T: Serialize + DeserializeOwned> Edit for TomlEditor<T>

source§

const EXTENSION: &'static str = "toml"

§

type T = T

§

type Err = EditError<Error>