IntoData

Trait IntoData 

Source
pub trait IntoData: Sized {
Show 13 methods // Required method fn into_data(self) -> Data; // Provided methods fn raw(self) -> Data { ... } fn unordered(self) -> Data { ... } fn is(self, format: DataFormat) -> Data { ... } fn is_json(self) -> Data { ... } fn json(self) -> Data { ... } fn is_jsonlines(self) -> Data { ... } fn json_lines(self) -> Data { ... } fn is_termsvg(self) -> Data { ... } fn term_svg(self) -> Data { ... } fn against(self, format: DataFormat) -> Data { ... } fn against_json(self) -> Data { ... } fn against_jsonlines(self) -> Data { ... }
}
Expand description

Convert to Data with modifiers for expected data

Required Methods§

Source

fn into_data(self) -> Data

Convert to Data, applying defaults

Provided Methods§

Source

fn raw(self) -> Data

Remove default filters from this expected result

Source

fn unordered(self) -> Data

Treat lines and json arrays as unordered

§Examples
use snapbox::prelude::*;
use snapbox::str;
use snapbox::assert_data_eq;

let actual = str![[r#"["world", "hello"]"#]]
    .is(snapbox::data::DataFormat::Json)
    .unordered();
let expected = str![[r#"["hello", "world"]"#]]
    .is(snapbox::data::DataFormat::Json)
    .unordered();
assert_data_eq!(actual, expected);
Source

fn is(self, format: DataFormat) -> Data

Initialize as format or Error

This is generally used for expected data

§Examples
use snapbox::prelude::*;
use snapbox::str;

let expected = str![[r#"{"hello": "world"}"#]]
    .is(snapbox::data::DataFormat::Json);
assert_eq!(expected.format(), snapbox::data::DataFormat::Json);
Source

fn is_json(self) -> Data

Initialize as json or Error

This is generally used for expected data

§Examples
use snapbox::prelude::*;
use snapbox::str;

let expected = str![[r#"{"hello": "world"}"#]]
    .is_json();
assert_eq!(expected.format(), snapbox::data::DataFormat::Json);
Source

fn json(self) -> Data

👎Deprecated since 0.6.13: Replaced with IntoData::is_json
Source

fn is_jsonlines(self) -> Data

Initialize as json lines or Error

This is generally used for expected data

§Examples
use snapbox::prelude::*;
use snapbox::str;

let expected = str![[r#"{"hello": "world"}"#]]
    .is_jsonlines();
assert_eq!(expected.format(), snapbox::data::DataFormat::JsonLines);
Source

fn json_lines(self) -> Data

👎Deprecated since 0.6.13: Replaced with IntoData::is_jsonlines
Source

fn is_termsvg(self) -> Data

Initialize as Term SVG

This is generally used for expected data

Source

fn term_svg(self) -> Data

👎Deprecated since 0.6.13: Replaced with IntoData::is_termsvg
Source

fn against(self, format: DataFormat) -> Data

Override the type this snapshot will be compared against

Normally, the actual data is coerced to IntoData::is. This allows overriding that so you can store your snapshot in a more readable, diffable format.

§Examples
use snapbox::prelude::*;
use snapbox::str;

let expected = str![[r#"{"hello": "world"}"#]]
    .against(snapbox::data::DataFormat::JsonLines);
Source

fn against_json(self) -> Data

Initialize as json or Error

This is generally used for expected data

§Examples
use snapbox::prelude::*;
use snapbox::str;

let expected = str![[r#"{"hello": "world"}"#]]
    .is_json();
Source

fn against_jsonlines(self) -> Data

Initialize as json lines or Error

This is generally used for expected data

§Examples
use snapbox::prelude::*;
use snapbox::str;

let expected = str![[r#"{"hello": "world"}"#]]
    .against_jsonlines();

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl IntoData for &str

Source§

impl IntoData for &String

Source§

impl IntoData for &[u8]

Source§

impl IntoData for String

Source§

impl IntoData for Vec<u8>

Implementors§