#[non_exhaustive]pub enum FormatError {
OutOfBounds {
start: u32,
end: u32,
len: usize,
},
NotCharBoundary {
offset: u32,
},
NotContiguous {
expected: u32,
found: u32,
},
}Expand description
Why format() could not format a tree.
The formatter accepts any tree shape, error nodes included; it refuses
only a tree whose tokens do not describe source, because formatting such a
tree would lose or invent text.
§Examples
use fmt_lang::syntax_lang::{Element, Node, Span, Token, TokenKind};
use fmt_lang::{format, FormatError, Style};
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
struct Word;
impl TokenKind for Word {}
// A token reaching past the end of the source.
let tree = Node::new(Word, vec![Element::Token(Token::new(Word, Span::new(0, 9)))]);
let err = format(&tree, "short", &Style::default(), 80).unwrap_err();
assert_eq!(err, FormatError::OutOfBounds { start: 0, end: 9, len: 5 });Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
OutOfBounds
A token’s span reaches past the end of the source. The tree was built
from different text; parse source again.
Fields
NotCharBoundary
A token boundary falls inside a multi-byte character. The tree was
built from different text; parse source again.
NotContiguous
Consecutive tokens leave a gap or overlap, so the tree is not lossless: text between them would be lost or written twice. Every byte of the tree’s range must belong to exactly one token (trivia included).
Trait Implementations§
Source§impl Clone for FormatError
impl Clone for FormatError
Source§impl Debug for FormatError
impl Debug for FormatError
Source§impl Display for FormatError
impl Display for FormatError
impl Eq for FormatError
Source§impl Error for FormatError
impl Error for FormatError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl PartialEq for FormatError
impl PartialEq for FormatError
impl StructuralPartialEq for FormatError
Auto Trait Implementations§
impl Freeze for FormatError
impl RefUnwindSafe for FormatError
impl Send for FormatError
impl Sync for FormatError
impl Unpin for FormatError
impl UnsafeUnpin for FormatError
impl UnwindSafe for FormatError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more