Savage: A Primitive Computer Algebra System in Rust

Savage Computer Algebra System

Savage is a new computer algebra system written from scratch in pure Rust. Its goals are correctness, simplicity, and usability, in that order. The entire system compiles to a single, dependency-free executable just 2.5 MB in size. While that executable will of course grow as Savage matures, the plan is to eventually deliver a useful computer algebra system in 5 MB or less.

Screenshot

The name "Savage" is a reference/homage to Sage, the leading open-source computer algebra system. Since Sage already exists and works very well, it would make no sense to attempt to create a clone of it. Instead, Savage aims to be something of an antithesis to Sage: Where Sage is a unified frontend to dozens of mathematics packages, Savage is a tightly-integrated, monolithic system. Where Sage covers many areas of mathematics, including cutting-edge research topics, Savage will focus on the "bread and butter" math employed by engineers and other people who use, rather than develop, mathematical concepts. Where Sage features amazingly sophisticated implementations of countless functions, Savage has code that is savagely primitive, getting the job done naively but correctly, without worrying whether the performance is still optimal when the input is a million-digit number.

Savage is in early development and is not yet ready to be used for serious work. It is, however, ready to play around with, and is happily accepting contributions to move the project forward.

Features

This is what Savage offers today:

  • Arbitrary-precision integer, rational, and complex arithmetic
  • Input, simplification, and evaluation of symbolic expressions
  • First-class support for vectors and matrices, with coefficients being arbitrary expressions
  • REPL with syntax and bracket highlighting, persistent history, and automatic multi-line input
  • Macro-based system for defining functions with metadata and automatic type checking
  • Usable as a library from any Rust program

The following features are planned, with some of the groundwork already done:

  • User-defined variables and functions
  • Built-in help system
  • Many more functions from various areas of math
  • More powerful expression simplification
  • Jupyter kernel

By contrast, the following are considered non-features for Savage, and there are no plans to add them either now or in the future:

  • Advanced/research-level mathematics: As a rule of thumb, if it doesn't belong in a typical undergraduate course, it probably doesn't belong in Savage.
  • Physics/finance/machine learning/other areas adjacent to math: The scope would grow without bounds and that is exactly what Savage aims to avoid.
  • Formal verification of implementations: The required technologies aren't mature yet and Savage is not a research project.
  • Performance at the expense of simplicity: Yes, I know that multiplication can be done faster using some fancy Fourier tricks. No, I won't implement that.
  • General-purpose programming: Too complex, and not the focus of this project.
  • File/network I/O: Savage performs computations, nothing more and nothing less. Functions have no side effects.
  • Modules/packages/extensions/plugins: The world is complicated enough. Either something is built in, or Savage doesn't have it at all.
  • GUI: Although it's possible to create a GUI frontend backed by the savage_core crate, there are no plans to do so within the Savage project itself.

Installation

Building Savage from source requires Rust 1.56 or later. Once a supported version of Rust is installed on your system, you only need to run

cargo install savage

to install the Savage REPL to your Cargo binary directory (usually $HOME/.cargo/bin). Of course, you can also just clone this repository and cargo run the REPL from the repository root.

In the future, there will be pre-built executables for major platforms available with every Savage release.

Tour

Arithmetic

Arithmetic operations in Savage have no precision limits (other than the amount of memory available in your system):

in: 1 + 1
out: 2

in: 1.1 ^ 100
out: 13780.612339822270184118337172089636776264331200038466433146477552154985209
5523076769401159497458526446001

in: 3 ^ 4 ^ 5
out: 373391848741020043532959754184866588225409776783734007750636931722079040617
26525122999368893880397722046876506543147515810872705459216085858135133698280918
73141917485942625809388070199519564042855718180410466812887974029255176680123406
17298396574731619152386723046235125934896058590588284654793540505936202376547807
44273058214452705898875625145281779341335214192074462302751872918543286237573706
39854853194764169262638199728870069070138992565242971985276987492741962768110607
02333710356481

Results are automatically printed in either fractional or decimal form, depending on whether the input contained fractions or decimal numbers:

in: 6/5 * 3
out: 18/5

in: 1.2 * 3
out: 3.6

The variable i is predefined to represent the imaginary unit, allowing for complex numbers to be entered using standard notation:

in: (1 + i) ^ 12
out: -64

Linear algebra

Vectors and matrices are first-class citizens in Savage and support the standard addition, subtraction, multiplication, and exponentiation operators. Coefficients can be arbitrary expressions:

in: [a, b] - [a, c]
out: [0, b - c]

in: [a, b, c] * 3
out: [a * 3, b * 3, c * 3]

in: [[1, 2], [3, 4]] * [5, 6]
out: [17, 39]

Determinants are evaluated symbolically:

in: det([[a, 2], [3, a]])
out: a ^ 2 - 6

Logic

The standard &&, ||, !, and comparison operators are available. Savage automatically evaluates many tautologies and contradictions, even in the presence of undefined variables:

in: a && true
out: a

in: a || true
out: true

in: a || !a
out: true

in: a < a
out: false

Number theory

Verify that the Mersenne number M31 is a prime number:

in: is_prime(2^31 - 1)
out: true

Compute the ten millionth prime number:

in: nth_prime(10^7)
out: 179424673

Compute the number of primes up to ten million:

in: prime_pi(10^7)
out: 664579

These functions for dealing with prime numbers are powered by the ultra-fast primal crate. Many more functions from number theory will be added to Savage in the future.

Savage as a library

All of Savage's actual computer algebra functionality is contained in the savage_core crate. That crate exposes everything necessary to build software that leverages symbolic math capabilities. Assuming savage_core has been added as a dependency to a crate's Cargo.toml, it can be used like this:

use std::collections::HashMap;

use savage_core::{expression::Expression, helpers::*};

fn main() {
    // Expressions can be constructed by parsing a string literal...
    let lhs = "det([[a, 2], [3, a]])".parse::<Expression>().unwrap();
    // ... or directly from code using helper functions.
    let rhs = pow(var("a"), int(2)) - int(6);

    let mut context = HashMap::new();
    // The context can be used to set the values of variables during evaluation.
    // Change "b" to "a" to see this in action!
    context.insert("b".to_owned(), int(3));

    assert_eq!(lhs.evaluate(context), Ok(rhs));
}

Please note that at this point, the primary purpose of the savage_core crate is to power the Savage REPL, so any use by third-party crates should be considered somewhat experimental. Note also that like the rest of Savage, savage_core is licensed under the terms of the AGPL, which imposes conditions on any dependent software that go beyond what is required by the more common permissive licenses. Make sure you understand the AGPL and its implications before adding savage_core as a dependency to your crate.

Acknowledgments

Savage stands on the shoulders of the giant that is the Rust ecosystem. Among the many third-party crates that Savage relies on, I want to highlight two that play a particularly important role:

  • num is the fundamental crate for all numeric computations in Savage. It provides the crucial BigInt type that enables standard arithmetic operations to be performed with arbitrary precision. num's code is of high quality and extremely well tested.
  • chumsky is the magic behind Savage's expression parser. I have looked at every parser crate currently available and found Chumsky's API to be by far the most intuitive. Furthermore, Chumsky's author is highly responsive on the issue tracker, and has personally helped me understand and resolve two major issues that arose during the development of Savage's parser.

License

Copyright © 2021-2022 Philipp Emanuel Weidmann (pew@worldwidemann.com)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

By contributing to this project, you agree to release your contributions under the same license.


Download Details:

Author: p-e-w
Source Code: https://github.com/p-e-w/savage

License: AGPL-3.0 license

#rust 

What is GEEK

Buddha Community

Savage: A Primitive Computer Algebra System in Rust

Serde Rust: Serialization Framework for Rust

Serde

*Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.*

You may be looking for:

Serde in action

Click to show Cargo.toml. Run this code in the playground.

[dependencies]

# The core APIs, including the Serialize and Deserialize traits. Always
# required when using Serde. The "derive" feature is only required when
# using #[derive(Serialize, Deserialize)] to make Serde work with structs
# and enums defined in your crate.
serde = { version = "1.0", features = ["derive"] }

# Each data format lives in its own crate; the sample code below uses JSON
# but you may be using a different one.
serde_json = "1.0"

 

use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
struct Point {
    x: i32,
    y: i32,
}

fn main() {
    let point = Point { x: 1, y: 2 };

    // Convert the Point to a JSON string.
    let serialized = serde_json::to_string(&point).unwrap();

    // Prints serialized = {"x":1,"y":2}
    println!("serialized = {}", serialized);

    // Convert the JSON string back to a Point.
    let deserialized: Point = serde_json::from_str(&serialized).unwrap();

    // Prints deserialized = Point { x: 1, y: 2 }
    println!("deserialized = {:?}", deserialized);
}

Getting help

Serde is one of the most widely used Rust libraries so any place that Rustaceans congregate will be able to help you out. For chat, consider trying the #rust-questions or #rust-beginners channels of the unofficial community Discord (invite: https://discord.gg/rust-lang-community), the #rust-usage or #beginners channels of the official Rust Project Discord (invite: https://discord.gg/rust-lang), or the #general stream in Zulip. For asynchronous, consider the [rust] tag on StackOverflow, the /r/rust subreddit which has a pinned weekly easy questions post, or the Rust Discourse forum. It's acceptable to file a support issue in this repo but they tend not to get as many eyes as any of the above and may get closed without a response after some time.

Download Details:
Author: serde-rs
Source Code: https://github.com/serde-rs/serde
License: View license

#rust  #rustlang 

Ruth  Nabimanya

Ruth Nabimanya

1620633584

System Databases in SQL Server

Introduction

In SSMS, we many of may noticed System Databases under the Database Folder. But how many of us knows its purpose?. In this article lets discuss about the System Databases in SQL Server.

System Database

Fig. 1 System Databases

There are five system databases, these databases are created while installing SQL Server.

  • Master
  • Model
  • MSDB
  • Tempdb
  • Resource
Master
  • This database contains all the System level Information in SQL Server. The Information in form of Meta data.
  • Because of this master database, we are able to access the SQL Server (On premise SQL Server)
Model
  • This database is used as a template for new databases.
  • Whenever a new database is created, initially a copy of model database is what created as new database.
MSDB
  • This database is where a service called SQL Server Agent stores its data.
  • SQL server Agent is in charge of automation, which includes entities such as jobs, schedules, and alerts.
TempDB
  • The Tempdb is where SQL Server stores temporary data such as work tables, sort space, row versioning information and etc.
  • User can create their own version of temporary tables and those are stored in Tempdb.
  • But this database is destroyed and recreated every time when we restart the instance of SQL Server.
Resource
  • The resource database is a hidden, read only database that holds the definitions of all system objects.
  • When we query system object in a database, they appear to reside in the sys schema of the local database, but in actually their definitions reside in the resource db.

#sql server #master system database #model system database #msdb system database #sql server system databases #ssms #system database #system databases in sql server #tempdb system database

Savage: A Primitive Computer Algebra System in Rust

Savage Computer Algebra System

Savage is a new computer algebra system written from scratch in pure Rust. Its goals are correctness, simplicity, and usability, in that order. The entire system compiles to a single, dependency-free executable just 2.5 MB in size. While that executable will of course grow as Savage matures, the plan is to eventually deliver a useful computer algebra system in 5 MB or less.

Screenshot

The name "Savage" is a reference/homage to Sage, the leading open-source computer algebra system. Since Sage already exists and works very well, it would make no sense to attempt to create a clone of it. Instead, Savage aims to be something of an antithesis to Sage: Where Sage is a unified frontend to dozens of mathematics packages, Savage is a tightly-integrated, monolithic system. Where Sage covers many areas of mathematics, including cutting-edge research topics, Savage will focus on the "bread and butter" math employed by engineers and other people who use, rather than develop, mathematical concepts. Where Sage features amazingly sophisticated implementations of countless functions, Savage has code that is savagely primitive, getting the job done naively but correctly, without worrying whether the performance is still optimal when the input is a million-digit number.

Savage is in early development and is not yet ready to be used for serious work. It is, however, ready to play around with, and is happily accepting contributions to move the project forward.

Features

This is what Savage offers today:

  • Arbitrary-precision integer, rational, and complex arithmetic
  • Input, simplification, and evaluation of symbolic expressions
  • First-class support for vectors and matrices, with coefficients being arbitrary expressions
  • REPL with syntax and bracket highlighting, persistent history, and automatic multi-line input
  • Macro-based system for defining functions with metadata and automatic type checking
  • Usable as a library from any Rust program

The following features are planned, with some of the groundwork already done:

  • User-defined variables and functions
  • Built-in help system
  • Many more functions from various areas of math
  • More powerful expression simplification
  • Jupyter kernel

By contrast, the following are considered non-features for Savage, and there are no plans to add them either now or in the future:

  • Advanced/research-level mathematics: As a rule of thumb, if it doesn't belong in a typical undergraduate course, it probably doesn't belong in Savage.
  • Physics/finance/machine learning/other areas adjacent to math: The scope would grow without bounds and that is exactly what Savage aims to avoid.
  • Formal verification of implementations: The required technologies aren't mature yet and Savage is not a research project.
  • Performance at the expense of simplicity: Yes, I know that multiplication can be done faster using some fancy Fourier tricks. No, I won't implement that.
  • General-purpose programming: Too complex, and not the focus of this project.
  • File/network I/O: Savage performs computations, nothing more and nothing less. Functions have no side effects.
  • Modules/packages/extensions/plugins: The world is complicated enough. Either something is built in, or Savage doesn't have it at all.
  • GUI: Although it's possible to create a GUI frontend backed by the savage_core crate, there are no plans to do so within the Savage project itself.

Installation

Building Savage from source requires Rust 1.56 or later. Once a supported version of Rust is installed on your system, you only need to run

cargo install savage

to install the Savage REPL to your Cargo binary directory (usually $HOME/.cargo/bin). Of course, you can also just clone this repository and cargo run the REPL from the repository root.

In the future, there will be pre-built executables for major platforms available with every Savage release.

Tour

Arithmetic

Arithmetic operations in Savage have no precision limits (other than the amount of memory available in your system):

in: 1 + 1
out: 2

in: 1.1 ^ 100
out: 13780.612339822270184118337172089636776264331200038466433146477552154985209
5523076769401159497458526446001

in: 3 ^ 4 ^ 5
out: 373391848741020043532959754184866588225409776783734007750636931722079040617
26525122999368893880397722046876506543147515810872705459216085858135133698280918
73141917485942625809388070199519564042855718180410466812887974029255176680123406
17298396574731619152386723046235125934896058590588284654793540505936202376547807
44273058214452705898875625145281779341335214192074462302751872918543286237573706
39854853194764169262638199728870069070138992565242971985276987492741962768110607
02333710356481

Results are automatically printed in either fractional or decimal form, depending on whether the input contained fractions or decimal numbers:

in: 6/5 * 3
out: 18/5

in: 1.2 * 3
out: 3.6

The variable i is predefined to represent the imaginary unit, allowing for complex numbers to be entered using standard notation:

in: (1 + i) ^ 12
out: -64

Linear algebra

Vectors and matrices are first-class citizens in Savage and support the standard addition, subtraction, multiplication, and exponentiation operators. Coefficients can be arbitrary expressions:

in: [a, b] - [a, c]
out: [0, b - c]

in: [a, b, c] * 3
out: [a * 3, b * 3, c * 3]

in: [[1, 2], [3, 4]] * [5, 6]
out: [17, 39]

Determinants are evaluated symbolically:

in: det([[a, 2], [3, a]])
out: a ^ 2 - 6

Logic

The standard &&, ||, !, and comparison operators are available. Savage automatically evaluates many tautologies and contradictions, even in the presence of undefined variables:

in: a && true
out: a

in: a || true
out: true

in: a || !a
out: true

in: a < a
out: false

Number theory

Verify that the Mersenne number M31 is a prime number:

in: is_prime(2^31 - 1)
out: true

Compute the ten millionth prime number:

in: nth_prime(10^7)
out: 179424673

Compute the number of primes up to ten million:

in: prime_pi(10^7)
out: 664579

These functions for dealing with prime numbers are powered by the ultra-fast primal crate. Many more functions from number theory will be added to Savage in the future.

Savage as a library

All of Savage's actual computer algebra functionality is contained in the savage_core crate. That crate exposes everything necessary to build software that leverages symbolic math capabilities. Assuming savage_core has been added as a dependency to a crate's Cargo.toml, it can be used like this:

use std::collections::HashMap;

use savage_core::{expression::Expression, helpers::*};

fn main() {
    // Expressions can be constructed by parsing a string literal...
    let lhs = "det([[a, 2], [3, a]])".parse::<Expression>().unwrap();
    // ... or directly from code using helper functions.
    let rhs = pow(var("a"), int(2)) - int(6);

    let mut context = HashMap::new();
    // The context can be used to set the values of variables during evaluation.
    // Change "b" to "a" to see this in action!
    context.insert("b".to_owned(), int(3));

    assert_eq!(lhs.evaluate(context), Ok(rhs));
}

Please note that at this point, the primary purpose of the savage_core crate is to power the Savage REPL, so any use by third-party crates should be considered somewhat experimental. Note also that like the rest of Savage, savage_core is licensed under the terms of the AGPL, which imposes conditions on any dependent software that go beyond what is required by the more common permissive licenses. Make sure you understand the AGPL and its implications before adding savage_core as a dependency to your crate.

Acknowledgments

Savage stands on the shoulders of the giant that is the Rust ecosystem. Among the many third-party crates that Savage relies on, I want to highlight two that play a particularly important role:

  • num is the fundamental crate for all numeric computations in Savage. It provides the crucial BigInt type that enables standard arithmetic operations to be performed with arbitrary precision. num's code is of high quality and extremely well tested.
  • chumsky is the magic behind Savage's expression parser. I have looked at every parser crate currently available and found Chumsky's API to be by far the most intuitive. Furthermore, Chumsky's author is highly responsive on the issue tracker, and has personally helped me understand and resolve two major issues that arose during the development of Savage's parser.

License

Copyright © 2021-2022 Philipp Emanuel Weidmann (pew@worldwidemann.com)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

By contributing to this project, you agree to release your contributions under the same license.


Download Details:

Author: p-e-w
Source Code: https://github.com/p-e-w/savage

License: AGPL-3.0 license

#rust 

Awesome  Rust

Awesome Rust

1654894080

Serde JSON: JSON Support for Serde Framework

Serde JSON

Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.

[dependencies]
serde_json = "1.0"

You may be looking for:

JSON is a ubiquitous open-standard format that uses human-readable text to transmit data objects consisting of key-value pairs.

{
    "name": "John Doe",
    "age": 43,
    "address": {
        "street": "10 Downing Street",
        "city": "London"
    },
    "phones": [
        "+44 1234567",
        "+44 2345678"
    ]
}

There are three common ways that you might find yourself needing to work with JSON data in Rust.

  • As text data. An unprocessed string of JSON data that you receive on an HTTP endpoint, read from a file, or prepare to send to a remote server.
  • As an untyped or loosely typed representation. Maybe you want to check that some JSON data is valid before passing it on, but without knowing the structure of what it contains. Or you want to do very basic manipulations like insert a key in a particular spot.
  • As a strongly typed Rust data structure. When you expect all or most of your data to conform to a particular structure and want to get real work done without JSON's loosey-goosey nature tripping you up.

Serde JSON provides efficient, flexible, safe ways of converting data between each of these representations.

Operating on untyped JSON values

Any valid JSON data can be manipulated in the following recursive enum representation. This data structure is serde_json::Value.

enum Value {
    Null,
    Bool(bool),
    Number(Number),
    String(String),
    Array(Vec<Value>),
    Object(Map<String, Value>),
}

A string of JSON data can be parsed into a serde_json::Value by the serde_json::from_str function. There is also from_slice for parsing from a byte slice &[u8] and from_reader for parsing from any io::Read like a File or a TCP stream.

use serde_json::{Result, Value};

fn untyped_example() -> Result<()> {
    // Some JSON input data as a &str. Maybe this comes from the user.
    let data = r#"
        {
            "name": "John Doe",
            "age": 43,
            "phones": [
                "+44 1234567",
                "+44 2345678"
            ]
        }"#;

    // Parse the string of data into serde_json::Value.
    let v: Value = serde_json::from_str(data)?;

    // Access parts of the data by indexing with square brackets.
    println!("Please call {} at the number {}", v["name"], v["phones"][0]);

    Ok(())
}

The result of square bracket indexing like v["name"] is a borrow of the data at that index, so the type is &Value. A JSON map can be indexed with string keys, while a JSON array can be indexed with integer keys. If the type of the data is not right for the type with which it is being indexed, or if a map does not contain the key being indexed, or if the index into a vector is out of bounds, the returned element is Value::Null.

When a Value is printed, it is printed as a JSON string. So in the code above, the output looks like Please call "John Doe" at the number "+44 1234567". The quotation marks appear because v["name"] is a &Value containing a JSON string and its JSON representation is "John Doe". Printing as a plain string without quotation marks involves converting from a JSON string to a Rust string with as_str() or avoiding the use of Value as described in the following section.

The Value representation is sufficient for very basic tasks but can be tedious to work with for anything more significant. Error handling is verbose to implement correctly, for example imagine trying to detect the presence of unrecognized fields in the input data. The compiler is powerless to help you when you make a mistake, for example imagine typoing v["name"] as v["nmae"] in one of the dozens of places it is used in your code.

Parsing JSON as strongly typed data structures

Serde provides a powerful way of mapping JSON data into Rust data structures largely automatically.

use serde::{Deserialize, Serialize};
use serde_json::Result;

#[derive(Serialize, Deserialize)]
struct Person {
    name: String,
    age: u8,
    phones: Vec<String>,
}

fn typed_example() -> Result<()> {
    // Some JSON input data as a &str. Maybe this comes from the user.
    let data = r#"
        {
            "name": "John Doe",
            "age": 43,
            "phones": [
                "+44 1234567",
                "+44 2345678"
            ]
        }"#;

    // Parse the string of data into a Person object. This is exactly the
    // same function as the one that produced serde_json::Value above, but
    // now we are asking it for a Person as output.
    let p: Person = serde_json::from_str(data)?;

    // Do things just like with any other Rust data structure.
    println!("Please call {} at the number {}", p.name, p.phones[0]);

    Ok(())
}

This is the same serde_json::from_str function as before, but this time we assign the return value to a variable of type Person so Serde will automatically interpret the input data as a Person and produce informative error messages if the layout does not conform to what a Person is expected to look like.

Any type that implements Serde's Deserialize trait can be deserialized this way. This includes built-in Rust standard library types like Vec<T> and HashMap<K, V>, as well as any structs or enums annotated with #[derive(Deserialize)].

Once we have p of type Person, our IDE and the Rust compiler can help us use it correctly like they do for any other Rust code. The IDE can autocomplete field names to prevent typos, which was impossible in the serde_json::Value representation. And the Rust compiler can check that when we write p.phones[0], then p.phones is guaranteed to be a Vec<String> so indexing into it makes sense and produces a String.

The necessary setup for using Serde's derive macros is explained on the Using derive page of the Serde site.

Constructing JSON values

Serde JSON provides a json! macro to build serde_json::Value objects with very natural JSON syntax.

use serde_json::json;

fn main() {
    // The type of `john` is `serde_json::Value`
    let john = json!({
        "name": "John Doe",
        "age": 43,
        "phones": [
            "+44 1234567",
            "+44 2345678"
        ]
    });

    println!("first phone number: {}", john["phones"][0]);

    // Convert to a string of JSON and print it out
    println!("{}", john.to_string());
}

The Value::to_string() function converts a serde_json::Value into a String of JSON text.

One neat thing about the json! macro is that variables and expressions can be interpolated directly into the JSON value as you are building it. Serde will check at compile time that the value you are interpolating is able to be represented as JSON.

let full_name = "John Doe";
let age_last_year = 42;

// The type of `john` is `serde_json::Value`
let john = json!({
    "name": full_name,
    "age": age_last_year + 1,
    "phones": [
        format!("+44 {}", random_phone())
    ]
});

This is amazingly convenient, but we have the problem we had before with Value: the IDE and Rust compiler cannot help us if we get it wrong. Serde JSON provides a better way of serializing strongly-typed data structures into JSON text.

Creating JSON by serializing data structures

A data structure can be converted to a JSON string by serde_json::to_string. There is also serde_json::to_vec which serializes to a Vec<u8> and serde_json::to_writer which serializes to any io::Write such as a File or a TCP stream.

use serde::{Deserialize, Serialize};
use serde_json::Result;

#[derive(Serialize, Deserialize)]
struct Address {
    street: String,
    city: String,
}

fn print_an_address() -> Result<()> {
    // Some data structure.
    let address = Address {
        street: "10 Downing Street".to_owned(),
        city: "London".to_owned(),
    };

    // Serialize it to a JSON string.
    let j = serde_json::to_string(&address)?;

    // Print, write to a file, or send to an HTTP server.
    println!("{}", j);

    Ok(())
}

Any type that implements Serde's Serialize trait can be serialized this way. This includes built-in Rust standard library types like Vec<T> and HashMap<K, V>, as well as any structs or enums annotated with #[derive(Serialize)].

Performance

It is fast. You should expect in the ballpark of 500 to 1000 megabytes per second deserialization and 600 to 900 megabytes per second serialization, depending on the characteristics of your data. This is competitive with the fastest C and C++ JSON libraries or even 30% faster for many use cases. Benchmarks live in the serde-rs/json-benchmark repo.

Getting help

Serde is one of the most widely used Rust libraries, so any place that Rustaceans congregate will be able to help you out. For chat, consider trying the #rust-questions or #rust-beginners channels of the unofficial community Discord (invite: https://discord.gg/rust-lang-community), the #rust-usage or #beginners channels of the official Rust Project Discord (invite: https://discord.gg/rust-lang), or the #general stream in Zulip. For asynchronous, consider the [rust] tag on StackOverflow, the /r/rust subreddit which has a pinned weekly easy questions post, or the Rust Discourse forum. It's acceptable to file a support issue in this repo, but they tend not to get as many eyes as any of the above and may get closed without a response after some time.

No-std support

As long as there is a memory allocator, it is possible to use serde_json without the rest of the Rust standard library. This is supported on Rust 1.36+. Disable the default "std" feature and enable the "alloc" feature:

[dependencies]
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }

For JSON support in Serde without a memory allocator, please see the serde-json-core crate.

Link: https://crates.io/crates/serde_json

#rust  #rustlang  #encode   #json 

Maddy Bris

Maddy Bris

1599132316

5Kw Solar System in Brisbane

1 August 2020, Sunny Sky solarannounced you to launch a residential solar power system in Queensland, Australia. There are different sizes of houses with different energy requirements so one solar power system cannot fulfill every type of electricity need.

Whether energy need is low or higher they have announced a wide range of solar power system in Brisbane that includes 5KW solar panel system, 6Kw solar panel system, 10Kw solar panel system, and many more so that everyone can enjoy the benefits of solar energy.

Residential Solar Power System needs to be flexible because of the changing requirement of energy. As we know our energy needs hikes up in the summers more than winters because we use air conditioners, refrigerators (also used in winters but less than summers), fans. In winter we drop down these usages so the energy needs to go up and down according to the weather changing.

Some households have a high energy need, some have low, and mostly have the normal or average of high and low. Sunny Sky Solar offers expert’s advice to all the customers on call or personally because it is important to analyze the energy need, budget, location, and many other things before buying a solar power system for your home sweet home.

Their professionals analyze all these things and suggest you the best residential solar power system in Brisbane to reduce the energy costs and clean the environment as solar energy is green & clean energy.

At this time of announcing the residential solar panel system, the representative of Sunny Sky Solar has talked about some advantages of a residential solar power system. He said “get update yourself by the time is important because the latest technology will save you lots of money and time. The solar power system is the best technology in this era that can give you lots of benefits. Don’t get upset with the initial cost because after installing a solar power system at your house it will repay you the initial cost in two to three years. So, you are going to invest in a great deal if you are purchasing a solar panel system in Brisbane.”

He also added “Residential solar power system can save your pocket from getting loose every month for heavy electricity bills. You will earn money by producing solar energy and feeding your power supply grid as government, and mostly all the power suppliers give benefits to producing solar energy. You can easily earn money by feeding the power grid with your excess produced solar energy. You will use solar energy and save the excess by feeding the power grid this way.”

Sunny Sky Solar offering an efficient range of residential and commercial solar power system that includes 5KW solar panel system, 6.6Kw solar panel system, 10Kw solar panel system, and there are many more that you can select according to your energy needs and budget.
They provide expert assistance that will help you in choosing the best solar system for your house. Their experienced professionals work under the guidance of experts who ensures the perfections and safety at the time of installing and after the installation.

Installing a solar power system at your place will be more convenient with them because they work under the expert’s supervision that makes them perfect and faster. They ensure safety first at the time of installing because at that time family members are around the installing site and accidents can happen.

They also ensure the quality of products they used in installing and other solar products. If the products will be durable and efficient, the system will produce more electricity with higher efficiency for a longer period.
The main thing that matters while installing a solar power system at a residence is the roof situation, Sunny Sky Solar doesn’t work for doing business only. They first check the place or analyze from your information that your location is safe for installing a solar power system or not. If the find any problem they will suggest repairing it first because if you will put the solar power system at a less secure place and the solar system’s weight can damage it then repairing that place first should your main priority.
This shows their loyalty and caring behavior towards the customers.

#solar panel system #solar panel system in brisbane #5kw solar panel system #5kw solar panel system #10kw solar panel system #10kw solar panel system in brisbane