Skip to content

Commit

Permalink
Small improvements to the adapter docs
Browse files Browse the repository at this point in the history
  • Loading branch information
juntyr committed Aug 6, 2024
1 parent 3e81647 commit d838840
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion crates/numcodecs-python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ serde = { workspace = true }
serde-transcode = { workspace = true }

[dev-dependencies]
pyo3 = { workspace = true, features = ["auto-initialize"] }
# pyo3 = { workspace = true, features = ["auto-initialize"] }
serde_json = { workspace = true, features = ["std"] }

[lints]
Expand Down
20 changes: 9 additions & 11 deletions crates/numcodecs-python/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use serde_transcode::transcode;

use crate::{PyCodec, PyCodecClass, PyCodecClassMethods, PyCodecMethods, PyCodecRegistry};

/// Wrapper around Python [`PyCodec`]s to use the Rust [`Codec`] API.
/// Wrapper around [`PyCodec`]s to use the [`Codec`] API.
pub struct PyCodecAdapter {
codec: Py<PyCodec>,
class: Py<PyCodecClass>,
Expand Down Expand Up @@ -49,7 +49,7 @@ impl PyCodecAdapter {
.map_err(serde::de::Error::custom)
}

/// Wraps a [`PyCodec`] to use the Rust [`Codec`] API.
/// Wraps a [`PyCodec`] to use the [`Codec`] API.
///
/// # Errors
///
Expand All @@ -65,13 +65,13 @@ impl PyCodecAdapter {
})
}

/// Access the wrapped [`PyCodec`] to use its Python [`PyCodecMethods`] API.
/// Access the wrapped [`PyCodec`] to use its [`PyCodecMethods`] API.
#[must_use]
pub fn as_codec<'py>(&self, py: Python<'py>) -> &Bound<'py, PyCodec> {
self.codec.bind(py)
}

/// Unwrap the [`PyCodec`] to use its Python [`PyCodecMethods`] API.
/// Unwrap the [`PyCodec`] to use its [`PyCodecMethods`] API.
#[must_use]
pub fn into_codec(self, py: Python) -> Bound<PyCodec> {
self.codec.into_bound(py)
Expand Down Expand Up @@ -375,15 +375,14 @@ impl DynCodec for PyCodecAdapter {
}
}

/// Wrapper around Python [`PyCodecClass`]es to use the Rust [`DynCodecType`]
/// API.
/// Wrapper around [`PyCodecClass`]es to use the [`DynCodecType`] API.
pub struct PyCodecClassAdapter {
class: Py<PyCodecClass>,
codec_id: Arc<String>,
}

impl PyCodecClassAdapter {
/// Wraps a [`PyCodecClass`] to use the Rust [`DynCodecType`] API.
/// Wraps a [`PyCodecClass`] to use the [`DynCodecType`] API.
///
/// # Errors
///
Expand All @@ -397,15 +396,14 @@ impl PyCodecClassAdapter {
})
}

/// Access the wrapped [`PyCodecClass`] to use its Python
/// [`PyCodecClassMethods`] API.
/// Access the wrapped [`PyCodecClass`] to use its [`PyCodecClassMethods`]
/// API.
#[must_use]
pub fn as_codec_class<'py>(&self, py: Python<'py>) -> &Bound<'py, PyCodecClass> {
self.class.bind(py)
}

/// Unwrap the [`PyCodecClass`] to use its Python [`PyCodecClassMethods`]
/// API.
/// Unwrap the [`PyCodecClass`] to use its [`PyCodecClassMethods`] API.
#[must_use]
pub fn into_codec_class(self, py: Python) -> Bound<PyCodecClass> {
self.class.into_bound(py)
Expand Down

0 comments on commit d838840

Please sign in to comment.