Docs
This commit is contained in:
		@ -4,14 +4,15 @@ use std::{fmt::Display, num::TryFromIntError};
 | 
				
			|||||||
/// Rust types and KCL types.
 | 
					/// Rust types and KCL types.
 | 
				
			||||||
#[derive(Debug, thiserror::Error)]
 | 
					#[derive(Debug, thiserror::Error)]
 | 
				
			||||||
pub enum Error {
 | 
					pub enum Error {
 | 
				
			||||||
 | 
					    /// Some error not covered by other cases.
 | 
				
			||||||
    #[error("{0}")]
 | 
					    #[error("{0}")]
 | 
				
			||||||
    Message(String),
 | 
					    Message(String),
 | 
				
			||||||
 | 
					    /// Number is too big.
 | 
				
			||||||
    #[error("Number is too big")]
 | 
					    #[error("Number is too big")]
 | 
				
			||||||
    NumberTooBig,
 | 
					    NumberTooBig,
 | 
				
			||||||
 | 
					    /// Invalid key for a KCL object.
 | 
				
			||||||
    #[error("You cannot use this as a key of a KCL object")]
 | 
					    #[error("You cannot use this as a key of a KCL object")]
 | 
				
			||||||
    InvalidKey,
 | 
					    InvalidKey,
 | 
				
			||||||
    #[error("Invalid syntax")]
 | 
					 | 
				
			||||||
    Syntax,
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl From<TryFromIntError> for Error {
 | 
					impl From<TryFromIntError> for Error {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,3 +1,9 @@
 | 
				
			|||||||
 | 
					//! # Serde KCL
 | 
				
			||||||
 | 
					//!
 | 
				
			||||||
 | 
					//! KCL (KittyCAD Language) has an object model similar to JSON.
 | 
				
			||||||
 | 
					//! This crate works similarly to serde_json.
 | 
				
			||||||
 | 
					#![deny(missing_docs)]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use serde::Serialize;
 | 
					use serde::Serialize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub use crate::{error::Error, object::Object, value::Value};
 | 
					pub use crate::{error::Error, object::Object, value::Value};
 | 
				
			||||||
 | 
				
			|||||||
@ -3,6 +3,7 @@ use crate::Object;
 | 
				
			|||||||
pub(crate) mod de;
 | 
					pub(crate) mod de;
 | 
				
			||||||
pub(crate) mod ser;
 | 
					pub(crate) mod ser;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Values that can be represented in KCL.
 | 
				
			||||||
#[derive(Debug, PartialEq)]
 | 
					#[derive(Debug, PartialEq)]
 | 
				
			||||||
pub enum Value {
 | 
					pub enum Value {
 | 
				
			||||||
    /// A value to use when the specific value isn't really important.
 | 
					    /// A value to use when the specific value isn't really important.
 | 
				
			||||||
@ -33,6 +34,7 @@ pub enum Value {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
macro_rules! impl_as {
 | 
					macro_rules! impl_as {
 | 
				
			||||||
    ($name:ident, $variant:ident, $return_type:ty) => {
 | 
					    ($name:ident, $variant:ident, $return_type:ty) => {
 | 
				
			||||||
 | 
					        /// If the KCL value matches this type, return it.
 | 
				
			||||||
        pub fn $name(&self) -> Option<&$return_type> {
 | 
					        pub fn $name(&self) -> Option<&$return_type> {
 | 
				
			||||||
            match self {
 | 
					            match self {
 | 
				
			||||||
                Self::$variant(x) => Some(x),
 | 
					                Self::$variant(x) => Some(x),
 | 
				
			||||||
@ -60,6 +62,7 @@ impl Value {
 | 
				
			|||||||
    impl_as!(as_array, Array, Vec<Value>);
 | 
					    impl_as!(as_array, Array, Vec<Value>);
 | 
				
			||||||
    impl_as!(as_object, Object, Object);
 | 
					    impl_as!(as_object, Object, Object);
 | 
				
			||||||
    impl_as!(as_binary, Bytes, Vec<u8>);
 | 
					    impl_as!(as_binary, Bytes, Vec<u8>);
 | 
				
			||||||
 | 
					    /// If the KCL value matches this type, return it.
 | 
				
			||||||
    pub fn as_unit(&self) -> Option<()> {
 | 
					    pub fn as_unit(&self) -> Option<()> {
 | 
				
			||||||
        match self {
 | 
					        match self {
 | 
				
			||||||
            Self::Unit => Some(()),
 | 
					            Self::Unit => Some(()),
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user