playground_api/endpoints/gist.rs
1use serde::{Deserialize, Serialize};
2use std::borrow::Cow;
3
4/// A request to create a new Gist on the Rust playground.
5///
6/// Contains the code snippet to be shared.
7#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
8pub struct GistCreateRequest<'a> {
9 /// The Rust code to include in the Gist.
10 pub code: Cow<'a, str>,
11}
12
13impl<'a> GistCreateRequest<'a> {
14 /// Creates a new [`GistCreateRequest`] with the given code.
15 ///
16 /// # Arguments
17 ///
18 /// * `code` - The Rust code to be included in the Gist.
19 ///
20 /// # Returns
21 ///
22 /// A new [`GistCreateRequest`] containing the provided code.
23 pub fn new(code: Cow<'a, str>) -> Self {
24 Self { code }
25 }
26}
27
28impl<'b> super::Request for GistCreateRequest<'b> {
29 fn endpoint<'a>(&self) -> super::Endpoints<'a> {
30 super::Endpoints::GistCreate
31 }
32}
33
34/// A response returned after creating or retrieving a Gist.
35///
36/// Contains the Gist's unique ID, URL, and the stored code.
37#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
38pub struct GistResponse<'a> {
39 /// The unique identifier of the Gist.
40 pub id: Cow<'a, str>,
41 /// The public URL of the Gist.
42 pub url: Cow<'a, str>,
43 /// The Rust code stored in the Gist.
44 pub code: Cow<'a, str>,
45}
46
47impl<'a> super::Response for GistResponse<'a> {}