Struct stam::TextResourceBuilder
source · pub struct TextResourceBuilder { /* private fields */ }Expand description
This is a helper structure to build TextResource instances in a builder pattern.
Example:
use stam::*;
let mut store = AnnotationStore::default();
store.insert(
TextResourceBuilder::new().with_id("testres").with_text(
"Hello world!",
).build().unwrap()
);Implementations§
source§impl TextResourceBuilder
impl TextResourceBuilder
pub fn new() -> Self
sourcepub fn from_txt_file(filename: &str, config: Config) -> Result<Self, StamError>
pub fn from_txt_file(filename: &str, config: Config) -> Result<Self, StamError>
Loads a resource from text file
sourcepub fn from_file(filename: &str, config: Config) -> Result<Self, StamError>
pub fn from_file(filename: &str, config: Config) -> Result<Self, StamError>
Load a resource from file. The extension determines the type (json for STAM JSON or plain text otherwise).
You also need to pass a configuration, for which you can often just use Config::default().
sourcepub fn with_id(self, id: impl Into<String>) -> Self
pub fn with_id(self, id: impl Into<String>) -> Self
Associate a public identifier with the resource
sourcepub fn with_config(self, config: Config) -> Self
pub fn with_config(self, config: Config) -> Self
Set a configuration to use for this resource
sourcepub fn with_filename(self, filename: impl Into<String>) -> Self
pub fn with_filename(self, filename: impl Into<String>) -> Self
Set the filename associated with the resource. This does NOT load
the resource from file, but merely sets up the association and where to write to.
Use Self::from_file() instead if you want to load from file.
sourcepub fn with_text(self, text: impl Into<String>) -> Self
pub fn with_text(self, text: impl Into<String>) -> Self
Explicitly sets the text for the resource
sourcepub fn build(self) -> Result<TextResource, StamError>
pub fn build(self) -> Result<TextResource, StamError>
Builds a new TextResource from TextResourceBuilder, consuming the latter
Trait Implementations§
source§impl Debug for TextResourceBuilder
impl Debug for TextResourceBuilder
source§impl Default for TextResourceBuilder
impl Default for TextResourceBuilder
source§fn default() -> TextResourceBuilder
fn default() -> TextResourceBuilder
source§impl<'de> Deserialize<'de> for TextResourceBuilder
impl<'de> Deserialize<'de> for TextResourceBuilder
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl FromJson for TextResourceBuilder
impl FromJson for TextResourceBuilder
source§fn from_json_file(filename: &str, config: Config) -> Result<Self, StamError>
fn from_json_file(filename: &str, config: Config) -> Result<Self, StamError>
Loads a Text Resource from a STAM JSON or plain text file file.
If the file is JSON, it file must contain a single object which has “@type”: “TextResource”
If include is true, the file will be included via the @include mechanism, and is kept external upon serialization
source§fn from_json_str(string: &str, config: Config) -> Result<Self, StamError>
fn from_json_str(string: &str, config: Config) -> Result<Self, StamError>
Loads a text resource from a STAM JSON string The string must contain a single object which has “@type”: “TextResource”
fn merge_json_file(&mut self, _filename: &str) -> Result<(), StamError>
fn merge_json_str(&mut self, _string: &str) -> Result<(), StamError>
source§impl TryFrom<TextResourceBuilder> for TextResource
impl TryFrom<TextResourceBuilder> for TextResource
Auto Trait Implementations§
impl Freeze for TextResourceBuilder
impl RefUnwindSafe for TextResourceBuilder
impl Send for TextResourceBuilder
impl Sync for TextResourceBuilder
impl Unpin for TextResourceBuilder
impl UnwindSafe for TextResourceBuilder
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
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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