From: Ian Jackson Date: Sat, 23 Apr 2022 19:19:23 +0000 (+0100) Subject: ambassador: Introduce dependency and make some traits delegatiable X-Git-Tag: otter-1.1.0~412 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=13805c8e7d9c0b96680be189cdbc48b5783baf49;p=otter.git ambassador: Introduce dependency and make some traits delegatiable fastsplit pieces are going to want to delegate everything. Not only is this a lot of typing, open-coding it risks bugs when new trait methods are added. Signed-off-by: Ian Jackson --- diff --git a/Cargo.lock b/Cargo.lock index 230f0354..27001818 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -287,6 +287,18 @@ dependencies = [ "alloc-no-stdlib", ] +[[package]] +name = "ambassador" +version = "0.3.0" +source = "git+https://github.com/ijackson/ambassador?rev=e4775f906a7987b294e87c05ab1e923de0cf6a3a#e4775f906a7987b294e87c05ab1e923de0cf6a3a" +dependencies = [ + "bytemuck", + "itertools", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "ansi_term" version = "0.12.1" @@ -529,6 +541,20 @@ name = "bytemuck" version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee1e0e2125faccb856bf10b0a9dfa89c4c718d05ef85580dfefbdf1c422ef801" +dependencies = [ + "bytemuck_derive", +] + +[[package]] +name = "bytemuck_derive" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "562e382481975bc61d11275ac5e62a19abd00b0547d99516a415336f183dcd0e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "byteorder" @@ -2637,6 +2663,7 @@ dependencies = [ name = "otter" version = "1.0.0" dependencies = [ + "ambassador", "anyhow", "async-condvar-fair", "backtrace", diff --git a/Cargo.toml b/Cargo.toml index 4d4ff58c..e45d45a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -89,6 +89,8 @@ vecdeque-stableix="1" xmlparser = "0.13" zip="0.6" +ambassador = { version = "0.3", git = "https://github.com/ijackson/ambassador", rev="e4775f906a7987b294e87c05ab1e923de0cf6a3a" } + async-condvar-fair = { version="0.2", features=["parking_lot_0_12"] } const-default = { version="1", features=["derive" ] } enum-map = { version="2" , features=["serde" ] } diff --git a/src/gamestate.rs b/src/gamestate.rs index 4caeddec..0c67d77a 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -153,6 +153,7 @@ pub trait PieceXData: Downcast + Debug + Send + 'static { } impl_downcast!(PieceXData); +#[ambassador::delegatable_trait] #[enum_dispatch] #[dyn_upcast] pub trait OutlineTrait: Debug + Sync + Send + 'static { @@ -183,6 +184,7 @@ pub struct UoDescription { pub wrc: WhatResponseToClientOp, } +#[ambassador::delegatable_trait] #[dyn_upcast] pub trait PieceBaseTrait: OutlineTrait + Send + Debug + 'static { /// By convention, occult face is nfaces-1 @@ -191,6 +193,7 @@ pub trait PieceBaseTrait: OutlineTrait + Send + Debug + 'static { fn itemname(&self) -> &str; } +#[ambassador::delegatable_trait] #[typetag::serde] // usual variable: p pub trait PieceTrait: PieceBaseTrait + Send + Debug + 'static { fn add_ui_operations(&self, _y: ShowUnocculted,