Skip to content

Example fails #18

@citizenrich

Description

@citizenrich

Hi, thanks for this project. I'm trying to run the simple example on the README and have an error. I wonder if there's something basic I'm missing or if there's some dependencies that require to be declared other than serdes and fhir.

$ cargo run
   Compiling fhir-rust v0.1.0 (/Users/richard/src/github.com/citizenrich/fhir-rust)
warning: unused imports: `Deserialize`, `Serialize`
 --> src/main.rs:2:13
  |
2 | use serde::{Deserialize, Serialize};
  |             ^^^^^^^^^^^  ^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error[E0277]: the trait bound `fhir::r4::core::Patient: Serialize` is not satisfied
    --> src/main.rs:10:46
     |
10   |     let patient_json = serde_json::to_string(&patient);
     |                        --------------------- ^^^^^^^^ the trait `Serialize` is not implemented for `fhir::r4::core::Patient`
     |                        |
     |                        required by a bound introduced by this call
     |
     = help: the following other types implement trait `Serialize`:
               &'a T
               &'a mut T
               ()
               (T0, T1)
               (T0, T1, T2)
               (T0, T1, T2, T3)
               (T0, T1, T2, T3, T4)
               (T0, T1, T2, T3, T4, T5)
             and 149 others
note: required by a bound in `serde_json::to_string`
    --> /Users/richard/.cargo/registry/src/github.com-1ecc6299db9ec823/serde_json-1.0.94/src/ser.rs:2141:17
     |
2141 |     T: ?Sized + Serialize,
     |                 ^^^^^^^^^ required by this bound in `serde_json::to_string`

error[E0277]: `Result<std::string::String, serde_json::Error>` doesn't implement `std::fmt::Display`
  --> src/main.rs:11:20
   |
11 |     println!("{}", patient_json);
   |                    ^^^^^^^^^^^^ `Result<std::string::String, serde_json::Error>` cannot be formatted with the default formatter
   |
   = help: the trait `std::fmt::Display` is not implemented for `Result<std::string::String, serde_json::Error>`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
   = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
warning: `fhir-rust` (bin "fhir-rust") generated 1 warning
error: could not compile `fhir-rust` due to 2 previous errors; 1 warning emitted

Code is:

use fhir;
use serde::{Deserialize, Serialize};

fn main() {
    println!("Hello, world!");

    let patient = fhir::r4::core::Patient {
        ..Default::default()
    };
    let patient_json = serde_json::to_string(&patient);
    println!("{}", patient_json);

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions