summaryrefslogtreecommitdiff
path: root/crates/tor-rpcbase/src/obj
Commit message (Collapse)AuthorAgeFilesLines
* tor-rpcbase: Removed dependency on `once_cell`hashcatHitman2025-06-141-2/+2
| | | | | | - Replaced `once_cell::sync::Lazy` with `std::sync::LazyLock`. Signed-off-by: hashcatHitman <[email protected]>
* Fix rustdoc errors from !2140.Nick Mathewson2024-05-091-2/+2
|
* RPC: Use one cast table entry per type.Nick Mathewson2024-05-091-29/+47
|
* tor-rpcbase: Add facility to downcast to Arc<dyn Trait>.Nick Mathewson2024-05-091-1/+55
| | | | | Previously we could only downcast to &dyn Trait, which is not adequate.
* rpc: Move deftly attributes into an `rpc` namespace.Nick Mathewson2024-04-111-2/+2
|
* Port many of the macros in tor-rpcbase to use derive-deftly.Nick Mathewson2024-04-041-44/+21
| | | | | | This simplifies our implementation logic in a few places, and simplifies our invocation syntax greatly. There are a few infelicities, noted in `TODO RPC` comments.
* Run maint/add_warning.Nick Mathewson2024-03-131-0/+1
|
* Run maint/add_warning to add lint block everywhereIan Jackson2023-08-231-0/+1
|
* Fix typosDimitris Apostolou2023-07-221-1/+1
|
* Run maint/add_warning to actually apply new lint allowsIan Jackson2023-07-101-0/+1
|
* rpc: Remove some verbiage about 'static, and demo that it's OK withoutIan Jackson2023-06-151-7/+15
| | | | | | | | | | | | | | It's now not actually possible to write code that doesn't work, even if `Tr` *isn't* 'static, because of the bounds on `CastTable::insert`. I tried to produce a non-working setup with a non-static `Simple`, but you can't implement `Object` for such a thing. Removing 'static from Object would stop the downcasts from Any to Object working. Prior to the new typesafe insert, this change - let f: fn(&dyn $crate::Object) -> &(dyn $traitname + 'static) = |self_| { + let f: fn(&dyn $crate::Object) -> &(dyn $traitname) = |self_| { would result in a runtime crash. Now it results in a compiler error.
* rpc: Give the name `O` to "the type associated with this CastTable"Ian Jackson2023-06-151-8/+12
| | | | | | | This was locally bound to `S` in one place. Bind and use it throughout. Since this is an RPC object, `O` is a better name. In each item, use the description once and thereafter just the name.
* rpc: Add Simple test case for CastTableIan Jackson2023-06-151-3/+20
|
* rpc: Move boxing from macro to CastTable::insert (formatting)Ian Jackson2023-06-151-3/+1
|
* rpc: Move boxing from macro to CastTable::insertIan Jackson2023-06-151-4/+4
|
* rpc: Make CastTable::insert be more type-safeIan Jackson2023-06-151-6/+21
| | | | This checks the Requirements.
* RPC: Functionality to downcast dyn Object to a dyn Trait.Nick Mathewson2023-06-121-0/+187
This is a rather tricky piece of functionality. It works as follows. We introduce a `CastTable` type. Each `CastTable` tells us how to downcast `dyn Object` for objects of a single concrete type. The `Object` type now has a `get_casttable` method that returns an empty `CastTable` by default. `CastTable` is, internally, a map from the `TypeId` of the target dyn Trait reference type to a function `fn(&dyn Object) -> &dyn Trait`. These functions are stored as `Box<dyn Any + ...>`. (They are Boxed because they may refer to generic functions, which you can't get a static reference to, and they're Any because the functions have different types.) The `decl_object!` macro now implements `get_casttable` as appropriate. (The syntax is a bit janky, but that's what we get for not using derive_adhoc.) For non-generic types, `get_casttable` uses a Lazy<CastTable>`. to initialize a CastTable exactly once. For generic types, it use a `Lazy<RwLock<HashMap<..>>` to build one CastTable per instantiation of the generic type. This could probably be optimized a bit more, the yaks could be shaved in a more scintillating hairstyle, and the syntax for generic `decl_object` could definitely be improved.