From f2533813ac4d92ff3733dc6c6041aa3a0c0b8b08 Mon Sep 17 00:00:00 2001 From: timofey Date: Sun, 30 Jul 2023 10:45:21 +0000 Subject: [PATCH] `Mode` docs --- src/rcore/modes.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/rcore/modes.rs b/src/rcore/modes.rs index 9f7a6af..3a096d8 100644 --- a/src/rcore/modes.rs +++ b/src/rcore/modes.rs @@ -4,11 +4,24 @@ use super::*; pub type ModeResult = Result<::ParseSuccess, E>; +/// Mode of parsing. pub trait Mode { + /// Successful parsing, may countain the parser itself + /// (`I`, usually [`Inlining`]). + /// + /// See [`FactoryParse::deserialize`]. type ParseSuccess; + /// Result of extending the value, failing sometimes or always. + /// + /// See [`FactoryParse::extend`]. type ExtensionResult; + /// Data enough to try extending the value. + /// + /// May be empty for always-failing extensions. + /// + /// See [`FactoryParse::extend`]. type ExtensionSource; fn bind( @@ -21,6 +34,7 @@ pub trait Mode { f: impl FnOnce(A0) -> A1, ) -> Self::ParseSuccess; + /// Discard any extra information contained in [`Mode::ParseSuccess`]. fn seal(s: Self::ParseSuccess) -> A; fn xmap_err( @@ -33,6 +47,7 @@ pub trait Mode { f: impl FnOnce(A0) -> Result, ) -> Self::ExtensionResult; + /// Convert [`Mode::ExtensionResult`] to [`Result`]. fn xseal(result: Self::ExtensionResult) -> Result; fn smap( @@ -42,6 +57,7 @@ pub trait Mode { fn prepare(a: A) -> Self::ExtensionSource; + /// For abstract [`FactoryParse::extend`] implementations. fn xsbind( ab: Self::ExtensionSource, t2ab: impl FnOnce(AB) -> (A, B),