qubit_codec/encoder.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2026 Haixing Hu.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10//! Encoder trait.
11
12/// Encodes a borrowed input value into another representation.
13pub trait Encoder<Input: ?Sized> {
14 /// Encoded output type.
15 type Output;
16 /// Encoding error type.
17 type Error;
18
19 /// Encodes `input`.
20 ///
21 /// # Parameters
22 /// - `input`: Source value to encode.
23 ///
24 /// # Returns
25 /// Encoded output.
26 ///
27 /// # Errors
28 /// Returns an error when the codec cannot represent the supplied input.
29 fn encode(&self, input: &Input) -> Result<Self::Output, Self::Error>;
30}