Skip to content

Commit 92a4ade

Browse files
committed
removed IsBinary
1 parent c674fc7 commit 92a4ade

3 files changed

Lines changed: 33 additions & 23 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
44
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

6+
## [0.2.0] - 2024-08-23
7+
8+
### Breaking Changes
9+
10+
- Trait `IsBinary` has been removed.
11+
- Instead, the traits `HybridEncoder` and `HybridDecoder` now provide the methods `is_binary_encoder` and
12+
`is_binary_decoder` respectively.
13+
614
## [0.1.2] - 2024-07-08
715

816
### New Codecs

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "codee"
3-
version = "0.1.2"
3+
version = "0.2.0"
44
edition = "2021"
55
authors = ["Marc-Stefan Cassola"]
66
categories = ["encoding"]

src/hybrid.rs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,6 @@
11
use crate::{Decoder, Encoder};
22
use thiserror::Error;
33

4-
pub trait IsBinary<T, E: ?Sized> {
5-
fn is_binary() -> bool;
6-
}
7-
8-
impl<D, T> IsBinary<T, [u8]> for D
9-
where
10-
D: Decoder<T, Encoded = [u8]>,
11-
{
12-
fn is_binary() -> bool {
13-
true
14-
}
15-
}
16-
17-
impl<D, T> IsBinary<T, str> for D
18-
where
19-
D: Decoder<T, Encoded = str>,
20-
{
21-
fn is_binary() -> bool {
22-
false
23-
}
24-
}
25-
264
#[derive(Debug, Error)]
275
pub enum HybridCoderError<E> {
286
#[error("Not implemented: {0}")]
@@ -34,6 +12,8 @@ pub enum HybridCoderError<E> {
3412
pub trait HybridDecoder<T, E: ?Sized> {
3513
type Error;
3614

15+
fn is_binary_decoder() -> bool;
16+
3717
fn decode_str(_val: &str) -> Result<T, HybridCoderError<Self::Error>> {
3818
Err(HybridCoderError::NotImplemented(
3919
"You're trying to decode from a string. This codec is binary.",
@@ -53,6 +33,11 @@ where
5333
{
5434
type Error = D::Error;
5535

36+
#[inline(always)]
37+
fn is_binary_decoder() -> bool {
38+
true
39+
}
40+
5641
fn decode_bin(val: &[u8]) -> Result<T, HybridCoderError<Self::Error>> {
5742
Ok(D::decode(val)?)
5843
}
@@ -64,6 +49,11 @@ where
6449
{
6550
type Error = D::Error;
6651

52+
#[inline(always)]
53+
fn is_binary_decoder() -> bool {
54+
false
55+
}
56+
6757
fn decode_str(val: &str) -> Result<T, HybridCoderError<Self::Error>> {
6858
Ok(D::decode(val)?)
6959
}
@@ -72,6 +62,8 @@ where
7262
pub trait HybridEncoder<T, E> {
7363
type Error;
7464

65+
fn is_binary_encoder() -> bool;
66+
7567
fn encode_str(_val: &T) -> Result<String, HybridCoderError<Self::Error>> {
7668
Err(HybridCoderError::NotImplemented(
7769
"You're trying to encode into a string. This codec is binary.",
@@ -91,6 +83,11 @@ where
9183
{
9284
type Error = E::Error;
9385

86+
#[inline(always)]
87+
fn is_binary_encoder() -> bool {
88+
true
89+
}
90+
9491
fn encode_bin(val: &T) -> Result<Vec<u8>, HybridCoderError<Self::Error>> {
9592
Ok(E::encode(val)?)
9693
}
@@ -102,6 +99,11 @@ where
10299
{
103100
type Error = E::Error;
104101

102+
#[inline(always)]
103+
fn is_binary_encoder() -> bool {
104+
false
105+
}
106+
105107
fn encode_str(val: &T) -> Result<String, HybridCoderError<Self::Error>> {
106108
Ok(E::encode(val)?)
107109
}

0 commit comments

Comments
 (0)