[obsidian] vault backup: 2023-09-01 18:57:37
This commit is contained in:
parent
8c29c1d863
commit
d30b091322
@ -23,25 +23,28 @@ Environmentは評価全体で見ればLetやLambdaごとに分岐していく構
|
|||||||
こんな感じすかねえ
|
こんな感じすかねえ
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
struct EnvironmentT<'a, T>(&'a mut Vec<(String, T)>, usize);
|
struct EnvironmentT<'a, T: Clone>(&'a mut Vec<(String, T)>, usize);
|
||||||
|
|
||||||
impl<'a, T> EnvironmentT<'a, T> {
|
impl<'a, T: Clone> EnvironmentT<'a, T> {
|
||||||
pub fn new(vec: &'a mut Vec<(String, T)>, mut names: Vec<(String, T)>) -> Self {
|
pub fn new(vec: &'a mut Vec<(String, T)>, mut names: Vec<(String, T)>) -> Self {
|
||||||
let len = vec.len();
|
let len = vec.len();
|
||||||
vec.append(&mut names);
|
vec.append(&mut names);
|
||||||
Self(vec, len)
|
Self(vec, len)
|
||||||
}
|
}
|
||||||
pub fn drop(&mut self) {
|
pub fn lookup(&self, name: &String) -> Option<T> {
|
||||||
self.0.truncate(self.1);
|
|
||||||
}
|
|
||||||
pub fn lookup(&self, name: &String) -> Option<&'a T> {
|
|
||||||
let res = self
|
let res = self
|
||||||
.0
|
.0
|
||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
.filter(|(n, _v)| name == n)
|
.filter(|(n, _v)| name == n)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
res.get(0).map(|(_, v)| v)
|
res.get(0).map(|(_, v)| v.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T: Clone> Drop for EnvironmentT<'a, T> {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.0.truncate(self.1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
Loading…
Reference in New Issue
Block a user