binding

Function binding 

Source
pub fn binding<T>(value: impl Into<T>) -> Binding<T>
where T: 'static + Clone,
Expand description

Creates a new binding from a value with automatic type conversion.

This function accepts any value that implements Into<T>, providing ergonomic initialization without manual conversion. Common use cases include:

  • binding("text") creates a Binding<String> from &str
  • binding(vec![1, 2, 3]) creates a Binding<Vec<i32>>
  • binding(42) creates a Binding<i32>

§Warning

This function rely on Rust’s type inference to determine the target type T. If the type cannot be inferred, you may need to provide an explicit type annotation.

§Examples

use nami::{binding, Binding};

// Automatic conversion from &str to String
let text: Binding<String> = binding("hello");
assert_eq!(text.get(), "hello");

// Direct initialization with owned types
let numbers: Binding<Vec<i32>> = binding(vec![1, 2, 3]);
assert_eq!(numbers.get(), vec![1, 2, 3]);

// Works with any type implementing Into
let count: Binding<i64> = binding(42i32); // i32 -> i64
assert_eq!(count.get(), 42i64);

This is equivalent to Binding::container(value.into()).