fidl_next_bind/
service.rs

1// Copyright 2024 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 core::marker::PhantomData;
6
7/// A FIDL service.
8pub trait Service {
9    /// The name of this service.
10    const SERVICE_NAME: &'static str;
11    /// The members of this service.
12    const MEMBER_NAMES: &'static [&'static str];
13}
14
15/// A strongly typed service instance.
16#[derive(Debug)]
17#[repr(transparent)]
18pub struct ServiceInstance<I, S> {
19    instance: I,
20    _service: PhantomData<S>,
21}
22
23impl<I, S> ServiceInstance<I, S> {
24    /// Returns a new service instance over the given instance.
25    pub fn from_untyped(instance: I) -> Self {
26        Self { instance, _service: PhantomData }
27    }
28
29    /// Returns a reference to the underlying instance.
30    pub fn as_untyped(&self) -> &I {
31        &self.instance
32    }
33}