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 edit
ed
See the module level docs for more information.
Required Associated Types§
sourcetype T
type T
Type returned from editing
This could be different from the type that is “passed in” to the implementor.
sourcetype Err: Error + From<IoError>
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§
Required Methods§
sourcefn write<W: Write>(&self, w: &mut W) -> Result<(), Self::Err>
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.
sourcefn read<C>(&self, content: String, con: &C) -> Option<Self::T>where
C: Conciliator + ?Sized,
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.