playground-api 0.5.1

Simple API-binding for The Rust Playground
Documentation
use serde::{Deserialize, Serialize};
use std::borrow::Cow;

/// A request to create a new Gist on the Rust playground.
///
/// Contains the code snippet to be shared.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct GistCreateRequest<'a> {
    /// The Rust code to include in the Gist.
    pub code: Cow<'a, str>,
}

impl<'a> GistCreateRequest<'a> {
    /// Creates a new [`GistCreateRequest`] with the given code.
    ///
    /// # Arguments
    ///
    /// * `code` - The Rust code to be included in the Gist.
    ///
    /// # Returns
    ///
    /// A new [`GistCreateRequest`] containing the provided code.
    pub fn new(code: Cow<'a, str>) -> Self {
        Self { code }
    }
}

impl<'b> super::Request for GistCreateRequest<'b> {
    fn endpoint<'a>(&self) -> super::Endpoints<'a> {
        super::Endpoints::GistCreate
    }
}

/// A response returned after creating or retrieving a Gist.
///
/// Contains the Gist's unique ID, URL, and the stored code.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct GistResponse<'a> {
    /// The unique identifier of the Gist.
    pub id: Cow<'a, str>,
    /// The public URL of the Gist.
    pub url: Cow<'a, str>,
    /// The Rust code stored in the Gist.
    pub code: Cow<'a, str>,
}

impl<'a> super::Response for GistResponse<'a> {}