Giter Club home page Giter Club logo

rust_structs's Introduction

println! uses a reference to data, not the data itself this means that references can be passed to println! then used later dbg! prints out data but is passed ownership unless otherwise specified as &(reference) update syntax allows us to avoid unnecessary rewriting of struct fields we do not want to update similar to spread syntax in js this println! macro uses the :? to tell println to display the second_user using the debug default formatting this uses a debug format that displays each field on its own line note that because we did not change the email field, my_user is no longer valid as a whole this is because we transferred ownership of the email field to second_user when using update syntax, references used in the previous instance of the struct will be destroyed if any fields that do not implement the Copy() trait (i.e. non-primitives) are not updated, then a new instacne is created with the updated values the following code is not allowed println!("{}", my_user.email); we can however reference the fields that were not transferred to second_user this derive statement applies to the User struct this allows for the use of Debug formatting with the println! macro this is an associated function similar to a static method, this is a function associated with the User struct this function does not accept a "self" arguent it returns "Self", a new instance of User this is a Tuple Struct no field names, just data types used to create a kind of Type this is a Unit-Like Struct behaves like a () unit

rust_structs's People

Contributors

roesnera avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.