pub struct len;
Expand description
Gets the length of a container or range
ⓘ
builtin! fn len (list) -> IResult<ConValue>
{
Ok(ConValue::Int(match list
{
ConValue::Empty => 0, ConValue::String(s) => s.chars().count() as _,
ConValue::Ref(r) => return len.call(env, slice::from_ref(r.as_ref())),
ConValue::Array(t) => t.len() as _, ConValue::Tuple(t) => t.len() as
_, ConValue::RangeExc(start, end) => (end - start) as _,
ConValue::RangeInc(start, end) => (end - start + 1) as _, _ =>
Err(Error::TypeError)?,
}))
}
Trait Implementations§
Source§impl Callable for len
impl Callable for len
Source§fn call(&self, env: &mut Environment, args: &[ConValue]) -> IResult<ConValue>
fn call(&self, env: &mut Environment, args: &[ConValue]) -> IResult<ConValue>
Calls this Callable in the provided Environment, with ConValue args
The Callable is responsible for checking the argument count and validating types
The Callable is responsible for checking the argument count and validating types
Auto Trait Implementations§
impl Freeze for len
impl RefUnwindSafe for len
impl Send for len
impl Sync for len
impl Unpin for len
impl UnwindSafe for len
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more