Skip to main content

Parser

Struct Parser 

Source
pub struct Parser<FS: FileSystem = NativeFs> { /* private fields */ }
Expand description

The OneNote file parser.

Use Parser::parse_notebook to load a notebook from a .onetoc2 file or Parser::parse_section to load a single .one section. These methods auto-detect OneNote 2016 (desktop) and OneDrive (FSSHTTP) formats and will return an error if the input is not the expected file type.

§Thread safety

The parser is stateless and can be shared across threads.

Implementations§

Source§

impl Parser<NativeFs>

Source

pub fn new() -> Parser<NativeFs>

Create a new OneNote file parser.

The parser holds no state; reuse a single instance across multiple parses if desired.

Source§

impl<FS: FileSystem> Parser<FS>

Source

pub fn new_with_fs(fs: FS) -> Parser<FS>

Create a new instance of the Parser struct using the provided file system.

§Parameters
  • fs: An instance of an object implementing the FileSystem trait. This parameter provides the necessary file system operations for the Parser.
Source

pub fn parse_notebook(&self, path: TypedPath<'_>) -> Result<Notebook>

Parse a OneNote notebook.

The path argument must point to a .onetoc2 file. This will parse the table of contents of the notebook as well as all contained sections from the folder that the table of contents file is in. Each returned Section carries its own Report of non-fatal warnings, reachable via Section::report.

Returns ErrorKind::NotATocFile if the file is not a notebook table of contents.

The notebook files are read on demand; mutating any of them while a parse is in progress, or while a derived crate::contents::Image / crate::contents::EmbeddedFile is alive, is unsupported.

Source

pub fn parse_section_buffer( self, data: &[u8], file_name: TypedPath<'_>, ) -> Result<Section>

Parse a OneNote section buffer.

The data argument must contain a OneNote section. The file_name is used to populate section metadata and error messages.

Returns ErrorKind::NotASectionFile if the buffer does not contain a section file.

Source

pub fn dump_onestore(&self, data: &[u8]) -> Result<String>

Parse the raw OneStore layer from a buffer and return its Debug representation.

Intended for tooling (e.g. the inspect binary) that needs to dump the low-level OneStore structures of a .one or .onetoc2 file without resolving them into the high-level Section / Notebook types. The exact format of the returned string is unstable and should not be parsed by scripts.

Source

pub fn parse_section(&self, path: TypedPath<'_>) -> Result<Section>

Parse a OneNote section file.

The path argument must point to a .one file that contains a OneNote section. The returned Section carries any non-fatal warnings encountered while parsing, reachable via Section::report.

Returns ErrorKind::NotASectionFile if the file does not contain a section.

The file is read on demand; mutating it while a parse is in progress, or while a derived attachment is alive, is unsupported.

Source

pub fn parse_package(&self, path: TypedPath<'_>) -> Result<Notebook>

Parse a OneNote package (.onepkg) file.

.onepkg files are CAB archives bundling a .onetoc2 plus its .one section files. This method decompresses the archive in memory and parses the contained notebook without writing anything to disk.

Returns ErrorKind::MalformedPackage if the file is not a valid cabinet or does not contain a .onetoc2 table of contents.

Trait Implementations§

Source§

impl Default for Parser<NativeFs>

Available on crate feature native-fs only.
Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<FS> Freeze for Parser<FS>
where FS: Freeze,

§

impl<FS> RefUnwindSafe for Parser<FS>
where FS: RefUnwindSafe,

§

impl<FS> Send for Parser<FS>

§

impl<FS> Sync for Parser<FS>

§

impl<FS> Unpin for Parser<FS>
where FS: Unpin,

§

impl<FS> UnsafeUnpin for Parser<FS>
where FS: UnsafeUnpin,

§

impl<FS> UnwindSafe for Parser<FS>
where FS: UnwindSafe,

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.