py-rs 0.1.1

generate python bindings from rust types
Documentation
#![allow(dead_code)]

use std::{concat, fs};

use py_rs::PY;

#[derive(PY)]
#[py(export_to = "export_manually/UserFile.ts")]
struct User {
    name: String,
    age: i32,
    active: bool,
}

#[derive(PY)]
#[py(export_to = "export_manually/dir/")]
struct UserDir {
    name: String,
    age: i32,
    active: bool,
}

#[test]
fn export_manually() {
    User::export().unwrap();

    let expected_content = if cfg!(feature = "format") {
        concat!(
            "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n",
            "export type User = { name: string; age: number; active: boolean };\n",
        )
    } else {
        concat!(
            "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n",
            "\nexport type User = { name: string, age: number, active: boolean, };",
            "\n",
        )
    };

    let actual_content = fs::read_to_string(User::default_output_path().unwrap()).unwrap();

    assert_eq!(actual_content, expected_content);
}

#[test]
fn export_manually_dir() {
    UserDir::export().unwrap();

    let expected_content = if cfg!(feature = "format") {
        concat!(
            "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\n",
            "export type UserDir = { name: string; age: number; active: boolean };\n",
        )
    } else {
        concat!(
            "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n",
            "\nexport type UserDir = { name: string, age: number, active: boolean, };",
            "\n",
        )
    };

    let actual_content = fs::read_to_string(UserDir::default_output_path().unwrap()).unwrap();

    assert_eq!(actual_content, expected_content);
}