Skip to content

Commit

Permalink
Add missing docs
Browse files Browse the repository at this point in the history
remove Payload::from_owner
  • Loading branch information
alexheretic authored and daniel-abramov committed Dec 14, 2024
1 parent f2b4519 commit 40d7dd6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Lightweight, flexible WebSockets for Rust.
#![deny(
// missing_docs,
missing_docs,
missing_copy_implementations,
missing_debug_implementations,
trivial_casts,
Expand Down
13 changes: 5 additions & 8 deletions src/protocol/frame/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{fmt::Display, mem};
pub struct Utf8Payload(Payload);

impl Utf8Payload {
/// Creates from a static str.
#[inline]
pub const fn from_static(str: &'static str) -> Self {
Self(Payload::Shared(Bytes::from_static(str.as_bytes())))
Expand All @@ -18,17 +19,20 @@ impl Utf8Payload {
self.0.as_slice()
}

/// Returns as a string slice.
#[inline]
pub fn as_str(&self) -> &str {
// safety: is valid uft8
unsafe { str::from_utf8_unchecked(self.as_slice()) }
}

/// Returns length in bytes.
#[inline]
pub fn len(&self) -> usize {
self.as_slice().len()
}

/// Returns true if the length is 0.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
Expand Down Expand Up @@ -124,19 +128,12 @@ pub enum Payload {
}

impl Payload {
/// Creates from static bytes.
#[inline]
pub const fn from_static(bytes: &'static [u8]) -> Self {
Self::Shared(Bytes::from_static(bytes))
}

#[inline]
pub fn from_owner<T>(owner: T) -> Self
where
T: AsRef<[u8]> + Send + 'static,
{
Self::Shared(Bytes::from_owner(owner))
}

/// Converts into [`Bytes`] internals & then clones (cheaply).
pub fn share(&mut self) -> Self {
match self {
Expand Down

0 comments on commit 40d7dd6

Please sign in to comment.