Skip to content

Commit

Permalink
Support capturing sequences without a serialization framework (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Mar 10, 2024
1 parent 85ea7c4 commit b415126
Show file tree
Hide file tree
Showing 15 changed files with 1,343 additions and 809 deletions.
31 changes: 13 additions & 18 deletions src/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,21 @@

use crate::std::fmt;

use super::internal::InternalVisitor;
use super::internal::{Internal, InternalVisitor};
use super::{Error, ValueBag};

impl<'v> ValueBag<'v> {
/// Get a value from a fillable slot.
pub const fn from_fill<T>(value: &'v T) -> Self
where
T: Fill,
{
ValueBag {
inner: Internal::Fill(value),
}
}
}

/// A type that requires extra work to convert into a [`ValueBag`](../struct.ValueBag.html).
///
/// This trait is an advanced initialization API.
Expand Down Expand Up @@ -151,23 +163,6 @@ mod tests {
);
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn fill_debug() {
struct TestFill;

impl Fill for TestFill {
fn fill(&self, slot: Slot) -> Result<(), Error> {
slot.fill_any(42u64)
}
}

assert_eq!(
format!("{:04?}", 42u64),
format!("{:04?}", ValueBag::from_fill(&TestFill)),
)
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn fill_fn_cast() {
Expand Down
Loading

0 comments on commit b415126

Please sign in to comment.