Struct SubplotDataFile

Source
pub struct SubplotDataFile { /* private fields */ }
Expand description

An embedded data file.

Embedded data files have names and content. The subplot template will generate a lazy_static containing all the data files embedded into the suite. Then generated test functions will extract data files

If you are using them in your test steps you should take them by value:

#[step]
fn step_using_a_file(context: &mut Context, somefile: SubplotDataFile) {
    // context.stash_file(somefile);
}

For the generated test to correctly recognise how to pass a file in, you must mark the argument as a file in your binding:

- when: using {somefile} as a input
  function: step_using_a_file
  types:
    somefile: file

Implementations§

Source§

impl SubplotDataFile

Source

pub fn new(name: &str, data: &str) -> Self

Construct a new data file object

Typically this will only be called from the generated test suite. The passed in name and data must be base64 encoded strings and each will be interpreted independently. The name will be treated as a PathBuf and the data will be stored as a slice of bytes.

Neither will be interpreted as utf8.


let data_file = SubplotDataFile::new("aGVsbG8=", "d29ybGQ=");
§Panics

This will panic if the passed in strings are not correctly base64 encoded.

Source

pub fn name(&self) -> &Path

Retrieve the filename

File names are returned as a borrow of a Path since they could be arbitrarily constructed, though typically they’ll have come from markdown source and so likely they will be utf-8 compatible.

let data_file = SubplotDataFile::new("aGVsbG8=", "d29ybGQ=");
assert_eq!(data_file.name().display().to_string(), "hello");
Source

pub fn data(&self) -> &[u8]

Retrieve the data

The data of a file is always returned as a slice of bytes. This is because files could be arbitrary data, though again, they typically will have been sourced from a Subplot document and so be utf-8 compatible.


let data_file = SubplotDataFile::new("aGVsbG8=", "d29ybGQ=");
assert_eq!(data_file.data(), b"world");

Trait Implementations§

Source§

impl Clone for SubplotDataFile

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SubplotDataFile

Source§

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

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

impl Default for SubplotDataFile

Source§

fn default() -> Self

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

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.