starnix_uapi/as_any.rs
1// Copyright 2023 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use std::any::Any;
6
7/// The `AsAny` trait enables callers to downcast a Trait into a concrete implementation, assuming
8/// the trait is `+ AsAny`.
9pub trait AsAny {
10 fn type_name(&self) -> &'static str {
11 std::any::type_name::<Self>()
12 }
13
14 fn as_any(&self) -> &dyn Any;
15}
16
17impl<T: Any> AsAny for T {
18 fn as_any(&self) -> &dyn Any {
19 self
20 }
21}