Module substudy::contexts
[−]
[src]
Iteration in context, with the previous and next value, if available.
use substudy::contexts::{Context, ItemsInContextExt}; let v: &[u8] = &[1, 2]; let ctxs: Vec<Context<u8>> = v.items_in_context() .map(|ctx| ctx.cloned()) .collect(); assert_eq!(v.len(), ctxs.len()); assert_eq!(None, ctxs[0].prev); assert_eq!(1, ctxs[0].curr); assert_eq!(Some(2), ctxs[0].next); assert_eq!(Some(1), ctxs[1].prev); assert_eq!(2, ctxs[1].curr); assert_eq!(None, ctxs[1].next);
This file would be pretty high-order magic in Haskell, where we wouldn't need to worry about the difference between values and references. In Rust, it's a bit like an evil hybrid of the abstraction of Haskell and the reference wonkiness of C++. It works well enough in practice, but I'm not sure how I feel about it.
Structs
Context |
An item in a slice, possibly with the item before or after it. |
ItemsInContext |
Iterator type for |
OptContext |
Like |
Traits
ItemsInContextExt |
Provides the |