Created
May 13, 2018 17:09
-
-
Save Stebalien/b90549f61e205eac2c738297c42393a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Iterable { | |
type Item; | |
fn map<T>(self, cb: fn(item: &Self::Item) -> T) -> Iterable<Item = T>; | |
fn skip(self, n: NonNegative) -> Iterable<Item = Self::Item>; | |
fn take(self, n: NonNegative) -> Iterable<Item = Self::Item>; | |
} | |
trait Collection: Iterable { | |
fn length(&self) -> NonNegative | |
} | |
struct Range { | |
start: NonNegative, | |
length: NonNegative, | |
} | |
trait IndexedCollection: Collection + Map<Key=NonNegative, Value=Self::Item> { | |
fn slice(self, range: Range) -> Option<IndexedCollection>; | |
fn splice(self, range: Range, Collection<Item=Self::Item>) -> Option<Collection<Item=Self::Item>> | |
} | |
trait Map { | |
type Key; | |
type Value; | |
fn get(&self, name: Self::Key) -> Option<Self::Value>; | |
fn update(self, name: Self::Key, value: Self::Value) -> Option<Map<Key=Self::Key, Value=Self::Value>>; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait FsObject { | |
fn created_at(&self) -> Time; | |
fn modified_at(&self) -> Time; | |
} | |
// Directories are collections of file objects. | |
// | |
// To *use* the file objects, you'll have to *cast* to a Directory, File, etc. | |
trait Directory: | |
Collection<Item = Cid<FsObject>> + Map<Key = String, Value = Cid<FsObject>> + FsObject | |
{ | |
} | |
trait RegularFile: FsObject + Collection<Item = u8> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct BasicRegularFile<C> { | |
data: C, | |
created: Time, | |
modified: Time, | |
} | |
impl<C> RegularFile for BasicRegularFile<C> | |
where | |
C: Collection<Item = u8>, | |
{ | |
// ... | |
} | |
impl<C> UpdatableRegularFile for BasicRegularFile<C> | |
where | |
C: UpdatableCollection<Item = u8>, | |
{ | |
// ... | |
} | |
struct Slice<T> { | |
data: [T], | |
range: Range, | |
} | |
impl<T> Collection for Slice<T> { | |
type Item = T; | |
//... | |
} | |
impl<T> UpdatableCollection for Slice<T> { | |
type Item = T; | |
//... | |
} | |
// Chunking.... | |
struct Cat<T> { | |
data: [Cid<Collection<Item = T>>], | |
} | |
impl<T> Collection for Cat<T> { | |
type Item = T; | |
//... | |
} | |
// Q: What about updating? Will probably need a wrapper type? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment