Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Commit 5ffb9d5

Browse files
committed
semaphore
1 parent edc2641 commit 5ffb9d5

File tree

3 files changed

+70
-27
lines changed

3 files changed

+70
-27
lines changed

.semaphore/semaphore.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# .semaphore/semaphore.yml
2+
version: v1.0
3+
name: serde_rustler
4+
agent:
5+
machine:
6+
type: e1-standard-2
7+
os_image: ubuntu1804
8+
blocks:
9+
- name: Install dependencies
10+
task:
11+
env_vars:
12+
- name: MIX_ENV
13+
value: test
14+
prologue:
15+
commands:
16+
- kiex install 1.8
17+
- sem-version elixir 1.8
18+
jobs:
19+
- name: mix and cache
20+
commands:
21+
- checkout
22+
# Be sure to use --force to skip confirmation prompts
23+
- mix local.hex --force
24+
- mix local.rebar --force
25+
- cache restore mix-deps-$SEMAPHORE_GIT_BRANCH-$(checksum mix.lock),mix-deps-$SEMAPHORE_GIT_BRANCH,mix-deps-master
26+
- cache restore mix-build-$SEMAPHORE_GIT_BRANCH-$(checksum mix.lock),mix-build-$SEMAPHORE_GIT_BRANCH,mix-build-master
27+
- mix do deps.get --all, compile
28+
- cache store mix-deps-$SEMAPHORE_GIT_BRANCH-$(checksum mix.lock) deps
29+
- cache store mix-build-$SEMAPHORE_GIT_BRANCH-$(checksum mix.lock) _build
30+
- name: Tests
31+
task:
32+
env_vars:
33+
- name: MIX_ENV
34+
value: test
35+
prologue:
36+
commands:
37+
- kiex install 1.8
38+
- sem-version elixir 1.8
39+
- checkout
40+
# Restore dependencies and compiled code
41+
- cache restore mix-deps-$SEMAPHORE_GIT_BRANCH-$(checksum mix.lock),mix-deps-$SEMAPHORE_GIT_BRANCH,mix-deps-master
42+
- cache restore mix-build-$SEMAPHORE_GIT_BRANCH-$(checksum mix.lock),mix-build-$SEMAPHORE_GIT_BRANCH,mix-build-master
43+
jobs:
44+
- name: Run Tests
45+
commands:
46+
- mix test

serde_rustler/src/de.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ use serde::{
1212
};
1313
use std::iter;
1414

15-
/**
16-
* Converts a native Elixir term to a native Rust type. See the [conversion table](https://github.com/sunny-g/serde_rustler/tree/master/serde_rustler#conversion-table) for details about deserialization behavior.
17-
*/
15+
/// Converts a native Elixir term to a native Rust type. See the [conversion table](https://github.com/sunny-g/serde_rustler/tree/master/serde_rustler#conversion-table) for details about deserialization behavior.
1816
#[inline]
1917
pub fn from_term<'de, 'a: 'de, T>(term: Term<'a>) -> Result<T, Error>
2018
where
@@ -437,7 +435,8 @@ impl<'de, 'a: 'de> de::Deserializer<'de> for Deserializer<'a> {
437435
}
438436
}
439437

440-
struct SequenceDeserializer<'a, I>
438+
/// SequenceDeserializer
439+
pub struct SequenceDeserializer<'a, I>
441440
where
442441
I: Iterator<Item = Term<'a>>,
443442
{
@@ -472,7 +471,8 @@ where
472471
}
473472
}
474473

475-
struct MapDeserializer<'a, I>
474+
/// MapDeserializer
475+
pub struct MapDeserializer<'a, I>
476476
where
477477
I: Iterator,
478478
{
@@ -544,15 +544,17 @@ where
544544
}
545545
}
546546

547-
enum EnumDeserializerType {
547+
/// EnumDeserializerType
548+
pub enum EnumDeserializerType {
548549
Any,
549550
Unit,
550551
Newtype,
551552
Tuple,
552553
Struct,
553554
}
554555

555-
struct EnumDeserializer<'a> {
556+
/// EnumDeserializer
557+
pub struct EnumDeserializer<'a> {
556558
variant_type: EnumDeserializerType,
557559
variant_term: Term<'a>,
558560
variant: String,
@@ -681,7 +683,7 @@ impl<'de, 'a: 'de> VariantAccess<'de> for EnumDeserializer<'a> {
681683
}
682684

683685
/// Deserializer for atoms and map keys.
684-
struct VariantNameDeserializer<'a> {
686+
pub struct VariantNameDeserializer<'a> {
685687
variant: Term<'a>,
686688
}
687689

serde_rustler/src/ser.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ use serde::{
55
serde_if_integer128,
66
};
77

8-
/**
9-
* Converts a native Rust type into a native Elixir term. See [conversion table](https://github.com/sunny-g/serde_rustler/tree/master/serde_rustler#conversion-table) for details about serialization behavior.
10-
*/
118
#[inline]
9+
/// Converts a native Rust type into a native Elixir term. See [conversion table](https://github.com/sunny-g/serde_rustler/tree/master/serde_rustler#conversion-table) for details about serialization behavior.
10+
///
1211
pub fn to_term<T>(env: Env, value: T) -> Result<Term, Error>
1312
where
1413
T: Serialize,
@@ -153,9 +152,9 @@ impl<'a> ser::Serializer for Serializer<'a> {
153152
self.serialize_unit()
154153
}
155154

155+
#[inline]
156156
/// Serializes `E::A` in `enum E { A, B }` as `:A` or `"A"`, depending on
157157
/// if the atom `:A` has already been created.
158-
#[inline]
159158
fn serialize_unit_variant(
160159
self,
161160
_name: &'static str,
@@ -165,10 +164,10 @@ impl<'a> ser::Serializer for Serializer<'a> {
165164
atoms::str_to_term(&self.env, variant).or(Err(Error::InvalidVariantName))
166165
}
167166

167+
#[inline]
168168
/// Serializes `struct Millimeters(u8)` as a tagged tuple:
169169
/// `{:Millimeters, u8}` or `{"Millimeters", u8}`, depending on if the atom
170170
/// `:Millimeters` has already been created.
171-
#[inline]
172171
fn serialize_newtype_struct<T>(
173172
self,
174173
name: &'static str,
@@ -183,11 +182,11 @@ impl<'a> ser::Serializer for Serializer<'a> {
183182
ser.to_tuple()
184183
}
185184

185+
#[inline]
186186
/// Serializes `E::N` in `enum E { N(u8) }` as a tagged tuple: `{:N, u8}`
187187
/// or `{"N", u8}`, depending on if the atom `:N` has already been created.
188188
/// Serializes `Result::Ok` and `Result::Err` of
189189
/// `enum Result { Ok(u8), Err(_) }` into `{:ok, u8}` or `{:err, _}`.
190-
#[inline]
191190
fn serialize_newtype_variant<T>(
192191
self,
193192
_name: &'static str,
@@ -205,21 +204,21 @@ impl<'a> ser::Serializer for Serializer<'a> {
205204
}
206205
}
207206

208-
/// Serializes sequences as a Elixir lists.
209207
#[inline]
208+
/// Serializes sequences as a Elixir lists.
210209
fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {
211210
Ok(SequenceSerializer::new(self, len, None))
212211
}
213212

214-
/// Serializes tuples as Elixir tuples.
215213
#[inline]
214+
/// Serializes tuples as Elixir tuples.
216215
fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple, Self::Error> {
217216
Ok(SequenceSerializer::new(self, Some(len), None))
218217
}
219218

219+
#[inline]
220220
/// Serializes `struct Rgb(u8, u8, u8)` as an Elixir Record or Record-like
221221
/// tuple: `{:Rgb, u8, u8, u8}` or `{"Rgb", u8, u8, u8}`.
222-
#[inline]
223222
fn serialize_tuple_struct(
224223
self,
225224
name: &'static str,
@@ -229,8 +228,8 @@ impl<'a> ser::Serializer for Serializer<'a> {
229228
Ok(SequenceSerializer::new(self, Some(len), Some(name_term)))
230229
}
231230

232-
/// Serializes `E::T` of `enum E { T(u8, u8) }` as an Elixir Record or Record-like tuple: `{:T, u8, u8}` or `{"T", u8, u8}`.
233231
#[inline]
232+
/// Serializes `E::T` of `enum E { T(u8, u8) }` as an Elixir Record or Record-like tuple: `{:T, u8, u8}` or `{"T", u8, u8}`.
234233
fn serialize_tuple_variant(
235234
self,
236235
_name: &'static str,
@@ -241,17 +240,17 @@ impl<'a> ser::Serializer for Serializer<'a> {
241240
self.serialize_tuple_struct(variant, len)
242241
}
243242

244-
/// Serializes map as Elixir map. Keys *will not* serialize into atoms.
245243
#[inline]
244+
/// Serializes map as Elixir map. Keys *will not* serialize into atoms.
246245
fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
247246
Ok(MapSerializer::new(self, len, None))
248247
}
249248

249+
#[inline]
250250
/// Serializes as map, but attempts to include
251251
/// `%{:__struct__ => :STRUCT_NAME}` or `${:__struct__ => "STRUCT_NAME"}`,
252252
/// if the atom `:STRUCT_NAME` has not already been created, and will also
253253
/// attempt to serialize keys as atoms.
254-
#[inline]
255254
fn serialize_struct(
256255
self,
257256
name: &'static str,
@@ -261,10 +260,10 @@ impl<'a> ser::Serializer for Serializer<'a> {
261260
Ok(MapSerializer::new(self, Some(len), Some(name_term)))
262261
}
263262

263+
#[inline]
264264
/// Serializes the same as we serialize a struct: `E::S` of
265265
/// `enum E { S { r: u8, g: u8, b: u8 } }` is a map including
266266
/// `%{:__struct__ => :S}` or `${:__struct__ => "S"}`.
267-
#[inline]
268267
fn serialize_struct_variant(
269268
self,
270269
_name: &'static str,
@@ -276,9 +275,7 @@ impl<'a> ser::Serializer for Serializer<'a> {
276275
}
277276
}
278277

279-
/**
280-
*
281-
*/
278+
/// SequenceSerializer
282279
pub struct SequenceSerializer<'a> {
283280
ser: Serializer<'a>,
284281
items: Vec<Term<'a>>,
@@ -388,9 +385,7 @@ impl<'a> ser::SerializeTupleVariant for SequenceSerializer<'a> {
388385
}
389386
}
390387

391-
/**
392-
*
393-
*/
388+
/// MapSerializer
394389
pub struct MapSerializer<'a> {
395390
ser: Serializer<'a>,
396391
name: Option<Term<'a>>,

0 commit comments

Comments
 (0)