jsonschema_rs 0.61.2 → 0.62.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +90 -1
- data/Cargo.toml +2 -2
- data/MIGRATION.md +10 -12
- data/README.md +43 -31
- data/ext/jsonschema/Cargo.lock +20 -20
- data/ext/jsonschema/Cargo.toml +3 -3
- data/lib/jsonschema/version.rb +1 -1
- data/sig/jsonschema.rbs +90 -63
- data/src/canonical.rs +19 -19
- data/src/error_kind.rs +4 -2
- data/src/evaluation.rs +4 -8
- data/src/lib.rs +16 -76
- data/src/options.rs +59 -29
- data/src/registry.rs +24 -3
- data/src/ser.rs +2 -424
- data/src/static_id.rs +2 -5
- metadata +2 -2
data/src/ser.rs
CHANGED
|
@@ -14,13 +14,9 @@ use serde::{
|
|
|
14
14
|
Serialize, Serializer,
|
|
15
15
|
};
|
|
16
16
|
use serde_json::{Map, Number, Value as JsonValue};
|
|
17
|
-
use std::{
|
|
18
|
-
cell::RefCell,
|
|
19
|
-
fmt::{self, Write},
|
|
20
|
-
};
|
|
17
|
+
use std::{cell::RefCell, fmt::Write};
|
|
21
18
|
|
|
22
19
|
static BIG_DECIMAL_CLASS: Lazy<RClass> = Lazy::new(|ruby| {
|
|
23
|
-
// Ensure bigdecimal is loaded
|
|
24
20
|
let _: Value = ruby
|
|
25
21
|
.eval("require 'bigdecimal'")
|
|
26
22
|
.expect("Failed to require bigdecimal");
|
|
@@ -722,8 +718,7 @@ fn convert_big_decimal(ruby: &Ruby, value: Value) -> Result<JsonValue, Error> {
|
|
|
722
718
|
))
|
|
723
719
|
}
|
|
724
720
|
|
|
725
|
-
/// Convert Ruby Integer to JSON
|
|
726
|
-
/// Handles Fixnum, Bignum, and arbitrary precision
|
|
721
|
+
/// Convert a Ruby Integer of any size to a JSON number.
|
|
727
722
|
#[inline]
|
|
728
723
|
fn convert_integer(ruby: &Ruby, value: Value) -> Result<JsonValue, Error> {
|
|
729
724
|
// Try i64 first (handles most integers including negative fixnums)
|
|
@@ -834,420 +829,3 @@ fn number_string_to_ruby(ruby: &Ruby, number: &str) -> Result<Value, Error> {
|
|
|
834
829
|
let _ = ruby.get_inner(&BIG_DECIMAL_CLASS);
|
|
835
830
|
ruby.module_kernel().funcall("BigDecimal", (number,))
|
|
836
831
|
}
|
|
837
|
-
|
|
838
|
-
/// Token used by serde_json with the `arbitrary_precision` feature.
|
|
839
|
-
const SERDE_JSON_NUMBER_TOKEN: &str = "$serde_json::private::Number";
|
|
840
|
-
|
|
841
|
-
#[derive(Debug)]
|
|
842
|
-
struct RubySerError(String);
|
|
843
|
-
|
|
844
|
-
impl fmt::Display for RubySerError {
|
|
845
|
-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
846
|
-
f.write_str(&self.0)
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
impl std::error::Error for RubySerError {}
|
|
851
|
-
|
|
852
|
-
impl serde::ser::Error for RubySerError {
|
|
853
|
-
fn custom<T: fmt::Display>(msg: T) -> Self {
|
|
854
|
-
RubySerError(msg.to_string())
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
/// A [`serde::Serializer`] that directly produces Ruby [`Value`] objects.
|
|
859
|
-
#[derive(Clone, Copy)]
|
|
860
|
-
struct RubySerializer<'a> {
|
|
861
|
-
ruby: &'a Ruby,
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
impl<'a> RubySerializer<'a> {
|
|
865
|
-
fn new(ruby: &'a Ruby) -> Self {
|
|
866
|
-
RubySerializer { ruby }
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
/// Parse a raw number string into a Ruby Integer, Float, or BigDecimal.
|
|
870
|
-
fn parse_number(&self, s: &str) -> Result<Value, RubySerError> {
|
|
871
|
-
number_string_to_ruby(self.ruby, s)
|
|
872
|
-
.map_err(|e| RubySerError(format!("number conversion failed: {e}")))
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
impl<'a> serde::Serializer for RubySerializer<'a> {
|
|
877
|
-
type Ok = Value;
|
|
878
|
-
type Error = RubySerError;
|
|
879
|
-
|
|
880
|
-
type SerializeSeq = RubySeqSerializer<'a>;
|
|
881
|
-
type SerializeTuple = RubySeqSerializer<'a>;
|
|
882
|
-
type SerializeTupleStruct = RubySeqSerializer<'a>;
|
|
883
|
-
type SerializeTupleVariant = RubySeqSerializer<'a>;
|
|
884
|
-
type SerializeMap = RubyMapSerializer<'a>;
|
|
885
|
-
type SerializeStruct = RubyStructSerializer<'a>;
|
|
886
|
-
type SerializeStructVariant = RubyStructSerializer<'a>;
|
|
887
|
-
|
|
888
|
-
#[inline]
|
|
889
|
-
fn serialize_bool(self, v: bool) -> Result<Value, RubySerError> {
|
|
890
|
-
Ok(self.ruby.into_value(v))
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
#[inline]
|
|
894
|
-
fn serialize_i8(self, v: i8) -> Result<Value, RubySerError> {
|
|
895
|
-
self.serialize_i64(i64::from(v))
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
#[inline]
|
|
899
|
-
fn serialize_i16(self, v: i16) -> Result<Value, RubySerError> {
|
|
900
|
-
self.serialize_i64(i64::from(v))
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
#[inline]
|
|
904
|
-
fn serialize_i32(self, v: i32) -> Result<Value, RubySerError> {
|
|
905
|
-
self.serialize_i64(i64::from(v))
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
#[inline]
|
|
909
|
-
fn serialize_i64(self, v: i64) -> Result<Value, RubySerError> {
|
|
910
|
-
Ok(self.ruby.into_value(v))
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
#[inline]
|
|
914
|
-
fn serialize_u8(self, v: u8) -> Result<Value, RubySerError> {
|
|
915
|
-
self.serialize_u64(u64::from(v))
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
#[inline]
|
|
919
|
-
fn serialize_u16(self, v: u16) -> Result<Value, RubySerError> {
|
|
920
|
-
self.serialize_u64(u64::from(v))
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
#[inline]
|
|
924
|
-
fn serialize_u32(self, v: u32) -> Result<Value, RubySerError> {
|
|
925
|
-
self.serialize_u64(u64::from(v))
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
#[inline]
|
|
929
|
-
fn serialize_u64(self, v: u64) -> Result<Value, RubySerError> {
|
|
930
|
-
Ok(self.ruby.integer_from_u64(v).as_value())
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
#[inline]
|
|
934
|
-
fn serialize_f32(self, v: f32) -> Result<Value, RubySerError> {
|
|
935
|
-
self.serialize_f64(f64::from(v))
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
#[inline]
|
|
939
|
-
fn serialize_f64(self, v: f64) -> Result<Value, RubySerError> {
|
|
940
|
-
Ok(self.ruby.into_value(v))
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
#[inline]
|
|
944
|
-
fn serialize_char(self, v: char) -> Result<Value, RubySerError> {
|
|
945
|
-
let mut buf = [0u8; 4];
|
|
946
|
-
Ok(self.ruby.into_value(v.encode_utf8(&mut buf) as &str))
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
#[inline]
|
|
950
|
-
fn serialize_str(self, v: &str) -> Result<Value, RubySerError> {
|
|
951
|
-
Ok(self.ruby.into_value(v))
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
fn serialize_bytes(self, v: &[u8]) -> Result<Value, RubySerError> {
|
|
955
|
-
Ok(self.ruby.str_from_slice(v).as_value())
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
#[inline]
|
|
959
|
-
fn serialize_none(self) -> Result<Value, RubySerError> {
|
|
960
|
-
Ok(self.ruby.qnil().as_value())
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
#[inline]
|
|
964
|
-
fn serialize_some<T: ?Sized + serde::Serialize>(
|
|
965
|
-
self,
|
|
966
|
-
value: &T,
|
|
967
|
-
) -> Result<Value, RubySerError> {
|
|
968
|
-
value.serialize(self)
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
#[inline]
|
|
972
|
-
fn serialize_unit(self) -> Result<Value, RubySerError> {
|
|
973
|
-
Ok(self.ruby.qnil().as_value())
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
#[inline]
|
|
977
|
-
fn serialize_unit_struct(self, _name: &'static str) -> Result<Value, RubySerError> {
|
|
978
|
-
Ok(self.ruby.qnil().as_value())
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
fn serialize_unit_variant(
|
|
982
|
-
self,
|
|
983
|
-
_name: &'static str,
|
|
984
|
-
_variant_index: u32,
|
|
985
|
-
variant: &'static str,
|
|
986
|
-
) -> Result<Value, RubySerError> {
|
|
987
|
-
Ok(self.ruby.into_value(variant))
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
fn serialize_newtype_struct<T: ?Sized + serde::Serialize>(
|
|
991
|
-
self,
|
|
992
|
-
name: &'static str,
|
|
993
|
-
value: &T,
|
|
994
|
-
) -> Result<Value, RubySerError> {
|
|
995
|
-
if name == SERDE_JSON_NUMBER_TOKEN {
|
|
996
|
-
// inner serializes as a raw number string.
|
|
997
|
-
// Serialize to Ruby String first, then parse as number.
|
|
998
|
-
let rb_str = value.serialize(self)?;
|
|
999
|
-
if let Some(rstring) = RString::from_value(rb_str) {
|
|
1000
|
-
let number = {
|
|
1001
|
-
// Copy bytes into an owned String before calling Ruby:
|
|
1002
|
-
// `parse_number` may invoke `Kernel.Integer` / `BigDecimal`,
|
|
1003
|
-
// so keeping an `as_slice` borrow alive would be unsound.
|
|
1004
|
-
// SAFETY: `rstring` is valid and we're in Ruby VM context.
|
|
1005
|
-
#[allow(unsafe_code)]
|
|
1006
|
-
let bytes = unsafe { rstring.as_slice() };
|
|
1007
|
-
std::str::from_utf8(bytes)
|
|
1008
|
-
.map(std::borrow::ToOwned::to_owned)
|
|
1009
|
-
.map_err(|_| {
|
|
1010
|
-
serde::ser::Error::custom("invalid arbitrary precision number")
|
|
1011
|
-
})?
|
|
1012
|
-
};
|
|
1013
|
-
return self.parse_number(&number);
|
|
1014
|
-
}
|
|
1015
|
-
return Err(serde::ser::Error::custom(
|
|
1016
|
-
"invalid arbitrary precision number",
|
|
1017
|
-
));
|
|
1018
|
-
}
|
|
1019
|
-
value.serialize(self)
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
fn serialize_newtype_variant<T: ?Sized + serde::Serialize>(
|
|
1023
|
-
self,
|
|
1024
|
-
_name: &'static str,
|
|
1025
|
-
_variant_index: u32,
|
|
1026
|
-
_variant: &'static str,
|
|
1027
|
-
value: &T,
|
|
1028
|
-
) -> Result<Value, RubySerError> {
|
|
1029
|
-
value.serialize(self)
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
fn serialize_seq(self, len: Option<usize>) -> Result<RubySeqSerializer<'a>, RubySerError> {
|
|
1033
|
-
let arr = match len {
|
|
1034
|
-
Some(n) => self.ruby.ary_new_capa(n),
|
|
1035
|
-
None => self.ruby.ary_new(),
|
|
1036
|
-
};
|
|
1037
|
-
Ok(RubySeqSerializer {
|
|
1038
|
-
ruby: self.ruby,
|
|
1039
|
-
arr,
|
|
1040
|
-
})
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
fn serialize_tuple(self, len: usize) -> Result<RubySeqSerializer<'a>, RubySerError> {
|
|
1044
|
-
self.serialize_seq(Some(len))
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
fn serialize_tuple_struct(
|
|
1048
|
-
self,
|
|
1049
|
-
_name: &'static str,
|
|
1050
|
-
len: usize,
|
|
1051
|
-
) -> Result<RubySeqSerializer<'a>, RubySerError> {
|
|
1052
|
-
self.serialize_seq(Some(len))
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
fn serialize_tuple_variant(
|
|
1056
|
-
self,
|
|
1057
|
-
_name: &'static str,
|
|
1058
|
-
_variant_index: u32,
|
|
1059
|
-
_variant: &'static str,
|
|
1060
|
-
len: usize,
|
|
1061
|
-
) -> Result<RubySeqSerializer<'a>, RubySerError> {
|
|
1062
|
-
self.serialize_seq(Some(len))
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
fn serialize_map(self, len: Option<usize>) -> Result<RubyMapSerializer<'a>, RubySerError> {
|
|
1066
|
-
let hash = match len {
|
|
1067
|
-
Some(n) => self.ruby.hash_new_capa(n),
|
|
1068
|
-
None => self.ruby.hash_new(),
|
|
1069
|
-
};
|
|
1070
|
-
Ok(RubyMapSerializer {
|
|
1071
|
-
ruby: self.ruby,
|
|
1072
|
-
hash,
|
|
1073
|
-
next_key: None,
|
|
1074
|
-
})
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
fn serialize_struct(
|
|
1078
|
-
self,
|
|
1079
|
-
_name: &'static str,
|
|
1080
|
-
len: usize,
|
|
1081
|
-
) -> Result<RubyStructSerializer<'a>, RubySerError> {
|
|
1082
|
-
Ok(RubyStructSerializer {
|
|
1083
|
-
ruby: self.ruby,
|
|
1084
|
-
hash: self.ruby.hash_new_capa(len),
|
|
1085
|
-
})
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
fn serialize_struct_variant(
|
|
1089
|
-
self,
|
|
1090
|
-
_name: &'static str,
|
|
1091
|
-
_variant_index: u32,
|
|
1092
|
-
_variant: &'static str,
|
|
1093
|
-
len: usize,
|
|
1094
|
-
) -> Result<RubyStructSerializer<'a>, RubySerError> {
|
|
1095
|
-
Ok(RubyStructSerializer {
|
|
1096
|
-
ruby: self.ruby,
|
|
1097
|
-
hash: self.ruby.hash_new_capa(len),
|
|
1098
|
-
})
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
/// Sequence serializer producing Ruby Arrays.
|
|
1103
|
-
struct RubySeqSerializer<'a> {
|
|
1104
|
-
ruby: &'a Ruby,
|
|
1105
|
-
arr: RArray,
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
impl serde::ser::SerializeSeq for RubySeqSerializer<'_> {
|
|
1109
|
-
type Ok = Value;
|
|
1110
|
-
type Error = RubySerError;
|
|
1111
|
-
|
|
1112
|
-
fn serialize_element<T: ?Sized + serde::Serialize>(
|
|
1113
|
-
&mut self,
|
|
1114
|
-
value: &T,
|
|
1115
|
-
) -> Result<(), RubySerError> {
|
|
1116
|
-
let v = value.serialize(RubySerializer::new(self.ruby))?;
|
|
1117
|
-
self.arr.push(v).map_err(serde::ser::Error::custom)
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
fn end(self) -> Result<Value, RubySerError> {
|
|
1121
|
-
Ok(self.arr.as_value())
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
|
-
impl serde::ser::SerializeTuple for RubySeqSerializer<'_> {
|
|
1126
|
-
type Ok = Value;
|
|
1127
|
-
type Error = RubySerError;
|
|
1128
|
-
|
|
1129
|
-
fn serialize_element<T: ?Sized + serde::Serialize>(
|
|
1130
|
-
&mut self,
|
|
1131
|
-
value: &T,
|
|
1132
|
-
) -> Result<(), RubySerError> {
|
|
1133
|
-
serde::ser::SerializeSeq::serialize_element(self, value)
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
fn end(self) -> Result<Value, RubySerError> {
|
|
1137
|
-
serde::ser::SerializeSeq::end(self)
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
impl serde::ser::SerializeTupleStruct for RubySeqSerializer<'_> {
|
|
1142
|
-
type Ok = Value;
|
|
1143
|
-
type Error = RubySerError;
|
|
1144
|
-
|
|
1145
|
-
fn serialize_field<T: ?Sized + serde::Serialize>(
|
|
1146
|
-
&mut self,
|
|
1147
|
-
value: &T,
|
|
1148
|
-
) -> Result<(), RubySerError> {
|
|
1149
|
-
serde::ser::SerializeSeq::serialize_element(self, value)
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
fn end(self) -> Result<Value, RubySerError> {
|
|
1153
|
-
serde::ser::SerializeSeq::end(self)
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
impl serde::ser::SerializeTupleVariant for RubySeqSerializer<'_> {
|
|
1158
|
-
type Ok = Value;
|
|
1159
|
-
type Error = RubySerError;
|
|
1160
|
-
|
|
1161
|
-
fn serialize_field<T: ?Sized + serde::Serialize>(
|
|
1162
|
-
&mut self,
|
|
1163
|
-
value: &T,
|
|
1164
|
-
) -> Result<(), RubySerError> {
|
|
1165
|
-
serde::ser::SerializeSeq::serialize_element(self, value)
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
fn end(self) -> Result<Value, RubySerError> {
|
|
1169
|
-
serde::ser::SerializeSeq::end(self)
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
|
-
/// Map serializer producing Ruby Hashes.
|
|
1174
|
-
struct RubyMapSerializer<'a> {
|
|
1175
|
-
ruby: &'a Ruby,
|
|
1176
|
-
hash: RHash,
|
|
1177
|
-
next_key: Option<Value>,
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
impl serde::ser::SerializeMap for RubyMapSerializer<'_> {
|
|
1181
|
-
type Ok = Value;
|
|
1182
|
-
type Error = RubySerError;
|
|
1183
|
-
|
|
1184
|
-
fn serialize_key<T: ?Sized + serde::Serialize>(&mut self, key: &T) -> Result<(), RubySerError> {
|
|
1185
|
-
self.next_key = Some(key.serialize(RubySerializer::new(self.ruby))?);
|
|
1186
|
-
Ok(())
|
|
1187
|
-
}
|
|
1188
|
-
|
|
1189
|
-
fn serialize_value<T: ?Sized + serde::Serialize>(
|
|
1190
|
-
&mut self,
|
|
1191
|
-
value: &T,
|
|
1192
|
-
) -> Result<(), RubySerError> {
|
|
1193
|
-
let key = self
|
|
1194
|
-
.next_key
|
|
1195
|
-
.take()
|
|
1196
|
-
.expect("serialize_value called without serialize_key");
|
|
1197
|
-
let val = value.serialize(RubySerializer::new(self.ruby))?;
|
|
1198
|
-
self.hash.aset(key, val).map_err(serde::ser::Error::custom)
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
|
-
fn end(self) -> Result<Value, RubySerError> {
|
|
1202
|
-
Ok(self.hash.as_value())
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
|
|
1206
|
-
/// Struct serializer producing Ruby Hashes with symbol keys.
|
|
1207
|
-
struct RubyStructSerializer<'a> {
|
|
1208
|
-
ruby: &'a Ruby,
|
|
1209
|
-
hash: RHash,
|
|
1210
|
-
}
|
|
1211
|
-
|
|
1212
|
-
impl serde::ser::SerializeStruct for RubyStructSerializer<'_> {
|
|
1213
|
-
type Ok = Value;
|
|
1214
|
-
type Error = RubySerError;
|
|
1215
|
-
|
|
1216
|
-
fn serialize_field<T: ?Sized + serde::Serialize>(
|
|
1217
|
-
&mut self,
|
|
1218
|
-
key: &'static str,
|
|
1219
|
-
value: &T,
|
|
1220
|
-
) -> Result<(), RubySerError> {
|
|
1221
|
-
let val = value.serialize(RubySerializer::new(self.ruby))?;
|
|
1222
|
-
let sym = self.ruby.sym_new(key);
|
|
1223
|
-
self.hash.aset(sym, val).map_err(serde::ser::Error::custom)
|
|
1224
|
-
}
|
|
1225
|
-
|
|
1226
|
-
fn end(self) -> Result<Value, RubySerError> {
|
|
1227
|
-
Ok(self.hash.as_value())
|
|
1228
|
-
}
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
impl serde::ser::SerializeStructVariant for RubyStructSerializer<'_> {
|
|
1232
|
-
type Ok = Value;
|
|
1233
|
-
type Error = RubySerError;
|
|
1234
|
-
|
|
1235
|
-
fn serialize_field<T: ?Sized + serde::Serialize>(
|
|
1236
|
-
&mut self,
|
|
1237
|
-
key: &'static str,
|
|
1238
|
-
value: &T,
|
|
1239
|
-
) -> Result<(), RubySerError> {
|
|
1240
|
-
serde::ser::SerializeStruct::serialize_field(self, key, value)
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
fn end(self) -> Result<Value, RubySerError> {
|
|
1244
|
-
serde::ser::SerializeStruct::end(self)
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1247
|
-
|
|
1248
|
-
/// Serialize any [`serde::Serialize`] type directly to a Ruby [`Value`].
|
|
1249
|
-
pub fn serialize_to_ruby<T: serde::Serialize>(ruby: &Ruby, value: &T) -> Result<Value, Error> {
|
|
1250
|
-
value
|
|
1251
|
-
.serialize(RubySerializer::new(ruby))
|
|
1252
|
-
.map_err(|err| Error::new(ruby.exception_runtime_error(), err.to_string()))
|
|
1253
|
-
}
|
data/src/static_id.rs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
//! Pre-interned Ruby symbol IDs for avoiding repeated `rb_intern` calls.
|
|
2
2
|
//!
|
|
3
|
-
//! Ruby's `rb_intern` does a hash table lookup
|
|
4
|
-
//!
|
|
5
|
-
//! repeated lookups in hot paths like error construction.
|
|
3
|
+
//! Ruby's `rb_intern` does a hash table lookup on every call. Each string here is interned once,
|
|
4
|
+
//! on first use, and its ID reused in hot paths such as error construction.
|
|
6
5
|
|
|
7
6
|
use std::num::NonZeroUsize;
|
|
8
7
|
|
|
@@ -74,8 +73,6 @@ impl IntoId for StaticId {
|
|
|
74
73
|
///
|
|
75
74
|
/// ```ignore
|
|
76
75
|
/// define_rb_intern!(static ID_MESSAGE: "@message");
|
|
77
|
-
/// // Use with funcall:
|
|
78
|
-
/// obj.funcall(*ID_ALLOCATE, ())?;
|
|
79
76
|
/// // Use with ivar_set:
|
|
80
77
|
/// obj.ivar_set(*ID_MESSAGE, value)?;
|
|
81
78
|
/// ```
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jsonschema_rs
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.62.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dmitry Dygalo
|
|
@@ -80,7 +80,7 @@ metadata:
|
|
|
80
80
|
homepage_uri: https://github.com/Stranger6667/jsonschema/tree/master/crates/jsonschema-rb
|
|
81
81
|
source_code_uri: https://github.com/Stranger6667/jsonschema
|
|
82
82
|
changelog_uri: https://github.com/Stranger6667/jsonschema/blob/master/crates/jsonschema-rb/CHANGELOG.md
|
|
83
|
-
documentation_uri: https://github.com/Stranger6667/jsonschema/blob/ruby-v0.
|
|
83
|
+
documentation_uri: https://github.com/Stranger6667/jsonschema/blob/ruby-v0.62.0/crates/jsonschema-rb/README.md
|
|
84
84
|
bug_tracker_uri: https://github.com/Stranger6667/jsonschema/issues
|
|
85
85
|
funding_uri: https://github.com/sponsors/Stranger6667
|
|
86
86
|
rubygems_mfa_required: 'true'
|