Skip to content

Commit

Permalink
rune: Clean up how protocols are registered
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Nov 1, 2024
1 parent f49d1da commit 0a1d4c5
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 173 deletions.
12 changes: 2 additions & 10 deletions book/src/traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,8 @@ let mut t = m.define_trait(["Iterator"])?;

t.handler(|cx| {
let next = cx.find(Protocol::NEXT)?;
cx.function_handler("next", &next)?;

let size_hint = if let Some(size_hint) = cx.try_find(Protocol::SIZE_HINT)? {
cx.function_handler("size_hint", &size_hint)?;
size_hint
} else {
let size_hint = cx.function("size_hint", |_: Value| (0usize, None::<usize>))?;
cx.function_handler(Protocol::SIZE_HINT, &size_hint)?;
size_hint
};

let size_hint = cx.find_or_define(Protocol::SIZE_HINT, |_: Value| (0usize, None::<usize>))?;

/* more methods */
Ok(())
Expand Down
Loading

0 comments on commit 0a1d4c5

Please sign in to comment.