Skip to content

Commit 93ffb18

Browse files
committed
Polish
1 parent d8382cb commit 93ffb18

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

book/src/types/scalars.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,15 @@ pub struct UserId(String);
8585
In case we need to customize [resolving][7] of a [custom GraphQL scalar][2] value (change the way it gets executed), the `#[graphql(to_output_with = <fn path>)]` attribute is the way to do so:
8686
```rust
8787
# extern crate juniper;
88-
# use juniper::{GraphQLScalar, ScalarValue, Value};
88+
# use juniper::{GraphQLScalar, IntoValue as _, ScalarValue, Value};
8989
#
9090
#[derive(GraphQLScalar)]
9191
#[graphql(to_output_with = to_output, transparent)]
9292
struct Incremented(i32);
9393

9494
/// Increments [`Incremented`] before converting into a [`Value`].
9595
fn to_output<S: ScalarValue>(v: &Incremented) -> Value<S> {
96-
let inc = v.0 + 1;
97-
Value::from(inc)
96+
(v.0 + 1).into_value()
9897
}
9998
#
10099
# fn main() {}

juniper/src/types/scalars.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ where
176176
type ArcStr = arcstr::ArcStr;
177177

178178
mod impl_arcstr_scalar {
179-
use crate::{InputValue, ScalarValue, Value};
179+
use crate::{InputValue, IntoValue as _, ScalarValue, Value};
180180

181181
use super::ArcStr;
182182

183183
pub(super) fn to_output<S: ScalarValue>(v: &ArcStr) -> Value<S> {
184-
Value::scalar(S::from_displayable(v))
184+
v.into_value()
185185
}
186186

187187
pub(super) fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<ArcStr, String> {
@@ -196,12 +196,12 @@ mod impl_arcstr_scalar {
196196
type CompactString = compact_str::CompactString;
197197

198198
mod impl_compactstring_scalar {
199-
use crate::{InputValue, ScalarValue, Value};
199+
use crate::{InputValue, IntoValue as _, ScalarValue, Value};
200200

201201
use super::CompactString;
202202

203203
pub(super) fn to_output<S: ScalarValue>(v: &CompactString) -> Value<S> {
204-
Value::scalar(S::from_displayable(v))
204+
v.into_value()
205205
}
206206

207207
pub(super) fn from_input<S: ScalarValue>(v: &InputValue<S>) -> Result<CompactString, String> {

0 commit comments

Comments
 (0)