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

source

pub fn new() -> Self

source

pub fn from_txt_file(filename: &str, config: Config) -> Result<Self, StamError>

Loads a resource from text file

source

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().

source

pub fn with_id(self, id: impl Into<String>) -> Self

Associate a public identifier with the resource

source

pub fn with_config(self, config: Config) -> Self

Set a configuration to use for this resource

source

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.

source

pub fn with_text(self, text: impl Into<String>) -> Self

Explicitly sets the text for the resource

source

pub fn build(self) -> Result<TextResource, StamError>

Builds a new TextResource from TextResourceBuilder, consuming the latter

Trait Implementations§

source§

impl Debug for TextResourceBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for TextResourceBuilder

source§

fn default() -> TextResourceBuilder

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

impl<'de> Deserialize<'de> for TextResourceBuilder

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl FromJson for TextResourceBuilder

source§

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>

Loads a text resource from a STAM JSON string The string must contain a single object which has “@type”: “TextResource”

source§

fn merge_json_file(&mut self, _filename: &str) -> Result<(), StamError>

source§

fn merge_json_str(&mut self, _string: &str) -> Result<(), StamError>

source§

impl TryFrom<TextResourceBuilder> for TextResource

§

type Error = StamError

The type returned in the event of a conversion error.
source§

fn try_from(builder: TextResourceBuilder) -> Result<Self, StamError>

Performs the conversion.
source§

impl TypeInfo for TextResourceBuilder

source§

fn typeinfo() -> Type

Return the type (introspection).
source§

fn temp_id_prefix() -> &'static str

Return the prefix for temporary identifiers of this type

Auto Trait Implementations§

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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,