Rust Tutorial #4 - Data Types

  Рет қаралды 92,951

Tech With Tim

Tech With Tim

Күн бұрын

Пікірлер: 92
@jankapko9338
@jankapko9338 2 жыл бұрын
Not sure if you were ever going to mention this, but you can actually print tuples, arrays and so forth. Instead of doing println!("{}", ('h', 'i', 1, 2, 3)), which would give you an error, you can use the debug print which has the following syntax: println!("{:?}", ('h', 'i', 1, 2, 3)) or println!("{:#?}", ('h', 'i', 1, 2, 3)), the latter one giving you a neatly formatted output. Overall a nice and informative video!
@TechWithTim
@TechWithTim 2 жыл бұрын
thank you! always appreciate the extra tips and hopefully this will help some people out in the comments :)
@gurnkerk3826
@gurnkerk3826 2 жыл бұрын
@@TechWithTim also you can implement the fmt::Display trait, so you decide how {} will show the tuple ;) for {:?} impl fmt::Debug
@razdevra6361
@razdevra6361 2 ай бұрын
@@gurnkerk3826 i really wanna learn this extra material would you like to be a part of my project
@interclosure
@interclosure Жыл бұрын
You actually CAN convert some int types, like in the case at the end of the video, this will work: let x: u8 = 4; let y: i32 = x as i32; OR let y: i32 = x.into(); Hope it helps
@madman777656
@madman777656 10 ай бұрын
I was actually just about to comment about how interesting it would’ve been if you couldn’t. Especially since coming from learning Java I’m used to the concept of putting a smaller box(u8) into a bigger box(i32) which should work. Thanks man!
@someaddictedidiot2186
@someaddictedidiot2186 9 ай бұрын
You are my savior!
@unstableisotopeiscool
@unstableisotopeiscool 9 ай бұрын
it says this in the error message
@shirazbabar8892
@shirazbabar8892 Жыл бұрын
At 4:28, I would like to provide a clarification. The accurate formula for determining the range is -(2^(n - 1)) to (2^(n - 1)) - 1. As a result, the range for the signed 8-bit integer (i8) would be -128 to 127.
@ethanmcintosh-locke8924
@ethanmcintosh-locke8924 Жыл бұрын
thank you, i was wondering why the rules were so loose when he was explaining it
@mbrav
@mbrav 2 жыл бұрын
You really hit on very important details that I have not seen in tutorials when I first tried Rust 5 months ago. Thanks!
@earlchesterantonio1581
@earlchesterantonio1581 2 жыл бұрын
Wow this tutorial series is very useful since i'm looking for a low level language to learn
@nickheyer
@nickheyer Жыл бұрын
Tim, I think you are confusing bool types in rust with other languages. A non-zero int does not mean true. In fact, if you attempted to declare 0 or 1 as a bool var as you did in your example, you'd get a compiler error: "expected 'bool' , found integer".
@bommanaakash5900
@bommanaakash5900 Жыл бұрын
yea
@grafsamuel2766
@grafsamuel2766 Жыл бұрын
confirmed
@ifeanyinneji7704
@ifeanyinneji7704 6 ай бұрын
Thanks
@oneilmw
@oneilmw Жыл бұрын
Very important for arrays: the type usize was not discussed. It is "basically a u32 or u64"*** variables with this type are unsigned integers, but have a bit-length which can vary based on the system it is compiled on. More specifically, they are unsigned integers of bit-length equal to ( the bit-length of a pointer at compile time ). usize is important to discuss early because it is the expected data type for the index argument of an array. Example: fn main() { let array_name: [u32; 3] = [0, 1, 2]; let index: usize = 2; let output: u32 = array_name[index]; println!("{}", output); }
@mukund4926
@mukund4926 2 жыл бұрын
hey Tim. can Rust replace C and C++ in the future? currently what kind of jobs use Rust?
@binds3063
@binds3063 2 жыл бұрын
Jobs in Rust now are pretty minimal atm afaik. But they are going up from what I have heard. I personally don’t think that many current projects in C and C++ will port over to Rust because that would kind of be unreasonable, but I do think Rust will probably be the way to go for systems programming in the future. I don’t really think that C or C++ can be fully replaced though. They are staples in the field of programming languages. Rust will definitely be a very big and widely used language in the future imo
@frroossst4267
@frroossst4267 2 жыл бұрын
C? not really, C++? many people tend to think so, like the creator of npm and deno, people wayyy smarter than me
@jma42
@jma42 2 жыл бұрын
most likely because of memory safety and tooling, the only stuff keeping them intact in c++ is because of library support that rust lacks. C is not going away. however I'm quite positive that rust might be going to be higher level in future and might even have the abstraction similar to python, while also retaining low-level control.
@marcotroster8247
@marcotroster8247 2 жыл бұрын
@Mukund I pretend that the application of Rust is mostly in low-level hardware drivers where correctness, pedantic precision and scientific programming matter. But you really need to have the personality to fit this kind of job and not get burned out. It's not always about job opportunities and money in software. The tasks arise from themselves if you wanna achieve certain goals. Languages are just tools, don't tunnel too much on learning them to perfection. Rather try to understand how a PC works. That's my best advice I can give 😉
@TeddieMovie
@TeddieMovie Жыл бұрын
@@marcotroster8247 very nicely said!
@dmaster20ify
@dmaster20ify 6 ай бұрын
the range of signed integers is implementation defined for compiled languages.
@hamdysaadpersonal
@hamdysaadpersonal 2 жыл бұрын
We need next how to convert between then easly , like string to i32 ,&str to String ; just something like that
@binds3063
@binds3063 2 жыл бұрын
&str to String would simply be calling to_string() on the &str. String to i32 would be through the parse method: let string_to_int = "10".to_string().parse().unwrap(); for example. Or with the turbo fish syntax to specify the type of F: let string_to_int = "10".to_string().parse::().unwrap();. parse will work for both &str and String.
@hamdysaadpersonal
@hamdysaadpersonal 2 жыл бұрын
@@binds3063 nice , i tried to make a program that takes a string then match it with the area of shapes , for example the user input is square so it will run other function called square(); that takes two other inputs then return the area ; anyway i'm stuck at the match thing because of the data types conversion .
@alienews0
@alienews0 4 ай бұрын
11:41 mm no warning despite u never read that tup before modifying it... That's one implicit promise of the debugger broken there ^^
@jasongracae1780
@jasongracae1780 2 жыл бұрын
Which font are you using?
@introspecticon
@introspecticon 2 жыл бұрын
Good video, but I don't understand why you left out strings. Coming from a Python background the difference between String objects and string literals in Rust was very unintuitive to me.
@TechWithTim
@TechWithTim 2 жыл бұрын
It will be explained in a future lesson!
@HughvanZyl
@HughvanZyl Жыл бұрын
I'd imagine "tuple" should actually be pronounced similarly to "to pull", according to English spelling rules. Because there is only a single "p", and the "u" is not the second last letter, the vowel makes a long sound, not short, and because there is a silent "e" at the end, the sound the vowel makes shifts, roughly from the sound it would make in a word like "up", to the sound it would make in a word like "mute".
@craftydoeseverything9718
@craftydoeseverything9718 9 ай бұрын
That is fair, however, the reason why it is usually pronounced with the "u" as in "up" is because the word "tuple" originates from words like "pentuple", "hextuple", "octuple", etc.
@eeronat
@eeronat 7 ай бұрын
There are three variants to the pronunciation, not two. All are used. The arguments are just for popcorn.
@HughvanZyl
@HughvanZyl 7 ай бұрын
@@eeronat k? Well i hope you enjoyed mine
@eeronat
@eeronat 7 ай бұрын
@@HughvanZyl sure did. You're a scholar.
@SlyPearTree
@SlyPearTree 2 жыл бұрын
This has nothing to do with Rust but I have to know: why does his start menu open every time he switch from his editor to an already opened console?
@letsgocamping88
@letsgocamping88 2 жыл бұрын
Thin he's hitting Windows key to show the task bar.
@frozenn00b
@frozenn00b Жыл бұрын
He uses Windows key to expose the task bar so he can use the mouse to switch to the command prompt instead of using the ALT+TAB key combination. Personally find it annoying, ALT+TAB has been around for decades, longer than the Windows key.
@subee128
@subee128 2 жыл бұрын
Thaanks
@albatroshd7945
@albatroshd7945 3 ай бұрын
8:23 as a German we spell tupel with a long u
@thewelder3538
@thewelder3538 5 ай бұрын
Just some feedback here. Firstly, if someone is unsure, they should probably use double over a float. So f64 if unsure rather than f32. You explanation of signed integer ranges is a little complex to someone who doesn't understand. -128 to -127 could look like it could simply store these two values. It actually might have been easier if you'd explained in-terms of the sign bit. If the top bit is set, it's considered to be negative and this way, it works for all sizes of integer, from i8 to i64 etc. Then when you discuss char, you don't actually say how many bits that char is. How would it deal with a unicode char? I'm not a Rust programmer, I've been a C++ dev for like 30+yrs at a well known software house but thought I'd check out your videos. They're good, but for someone who knows how to code, they'll have a lot of questions you don't answer. As an example, when you talk about bool, you say 0 is false and 1 is true... But is 2 true? In C++ anything other than zero is true.
@bradfin12
@bradfin12 4 ай бұрын
I32 contains whole numbers but only half of the possible values are whole. u32 are all whole numbers.
@mortaldev4999
@mortaldev4999 2 жыл бұрын
If i have a tupple with type (i32,bool,char) then does rhe sequence matter
@Royaleah
@Royaleah 2 жыл бұрын
;good videos;
@ryanbohling7699
@ryanbohling7699 4 ай бұрын
Is the reason i8 range is -128 to 127 instead of -255 to 255 because the minus sign is taking a bit?
@TechWithTim
@TechWithTim 4 ай бұрын
Yep!
@ryanbohling7699
@ryanbohling7699 4 ай бұрын
Perfect. Thanks dude!
@DuyTran-ss4lu
@DuyTran-ss4lu 2 жыл бұрын
Cool
@init1508
@init1508 2 жыл бұрын
So tuples are mutable while arrays are not, totally different from python
@zarith
@zarith 2 жыл бұрын
13:57
@miguelguthridge
@miguelguthridge 2 жыл бұрын
No, tuples are immutable by default, just like in Python (although unlike Python they can be made mutable). They are always fixed length though.
@init1508
@init1508 2 жыл бұрын
@@zarith Oh thanks a lot
@init1508
@init1508 2 жыл бұрын
@@miguelguthridge thanks!
@ohwow2074
@ohwow2074 2 жыл бұрын
Everything is immutable by default. So are the tuples
@xxorza
@xxorza Жыл бұрын
So I spend about 40 minutes on these videos, but then switched tab to my paid chatGPT and my learning got much faster. Thanks for your work, though.
@faatemehch96
@faatemehch96 11 ай бұрын
👍🏻
@willsterjohnson
@willsterjohnson Жыл бұрын
"too-pul" and "tuh-pl" are both correct pronunciations of tuple. Just like "om-ni-puh-tunt" and "om-nee-poh-tunt" are both correct pronunciations of omnipotent. What *is* an incorrect pronunciation though is "pro-nown-see-ay-shun", the correct way is "pro-nun-see-ay-shun"
@madhuvarun2790
@madhuvarun2790 Жыл бұрын
How are you getting autocomplete feature?
@kartikchauhan2778
@kartikchauhan2778 2 жыл бұрын
What is the use and applications of rust ??
@nanulanu
@nanulanu 2 жыл бұрын
basically everything, for example Pop_OS! is rewriting their whole GNU/Linux based OS in rust, because it is a very fast language
@nanulanu
@nanulanu 2 жыл бұрын
@@user-se6in3lb9s I didn’t say it’s the fastest, I just said it’s very fast
@binds3063
@binds3063 2 жыл бұрын
Systems programming, backend web development, front end web development (with WASM), cross-platform app development, block chain/web 3 development, etc. it is a general purpose language
@jdf026
@jdf026 2 жыл бұрын
smart contract writing for Solana
@frozenn00b
@frozenn00b Жыл бұрын
@@nanulanu No, Linux is not rewriting the entire OS to be Rust. Hell, the kernel is barely getting limited Rust *support* in 6.1. C/C++ isn't going anywhere for a long time. Pop_OS! is rewriting their window manager (GUI shell) in Rust, but that's not "whole GNU/Linux based OS".. that's an application.
@sepsmusic
@sepsmusic 2 жыл бұрын
it's not a tupple it's a tuple
@johnnytoobad7785
@johnnytoobad7785 2 жыл бұрын
Does Python have an interface for Rust or vice-versa ?
@ya4dang1
@ya4dang1 Жыл бұрын
Anyone find that popping menu distracting?
@grzegorzryznar5101
@grzegorzryznar5101 11 ай бұрын
Seems weird why elements from tuples is accessed by attribute and not by index
@gabiold
@gabiold 6 ай бұрын
Probably because it is semantically closer to a struct with unnamed members than to an array of alike elements.
@lsatenstein
@lsatenstein Жыл бұрын
How do I pin your KZbin channel to my cellphone. I am just auditing your course. I am an 83 years young senior. I have been doing software engineering for the past 55 years. My favorite language is C.
@antilogism
@antilogism 11 ай бұрын
I've 'been coding C for 37 years (with some VHDL, Octave/Matlab & Python projects for work and some OpenSCAD on the side). This is way different but I like it so far.
@kutoru
@kutoru Жыл бұрын
3:12 WYSI
@worldhack.1201
@worldhack.1201 2 жыл бұрын
Where we can use rust except desktop applications?
@jankapko9338
@jankapko9338 2 жыл бұрын
Rust is a low level programming language so you could write anything from an operating system, a video game, a graphical desktop application to a dynamic website.
@iamworstgamer
@iamworstgamer Жыл бұрын
which theme you are using in vscode
@ssisaias
@ssisaias Ай бұрын
is it Sublime Text, not vscode
@liambarrack8914
@liambarrack8914 10 ай бұрын
too-ple gang
@NouifrUIwefdf
@NouifrUIwefdf Жыл бұрын
He is wrong about booleans. Rust is very explicit, "bool" has to be "true" OR "false" and nothing else, not even 0 or 1.
@pwnwriter
@pwnwriter Жыл бұрын
10:40 You didn't see the original documentation 🙊 Nvm
@isaacslemko7947
@isaacslemko7947 Жыл бұрын
The fact that I taught myself binary to a T when I was 10, makes this so much easier
@mister_byte_
@mister_byte_ 8 ай бұрын
musturd
@fireplank7520
@fireplank7520 2 жыл бұрын
Hi! you accidentally leaked every video by linking it at the end lol. oops!
@bombrman1994
@bombrman1994 Жыл бұрын
If parimagen heard u call it mutt he will be pissed
@antilogism
@antilogism 11 ай бұрын
I figured you were referencing Mutt's creator but that's Michael Elkins. Who's Parimagen?
@bombrman1994
@bombrman1994 11 ай бұрын
@@antilogism primagen 😅
@kazuhah1743
@kazuhah1743 Жыл бұрын
not that it matters much, but tuple is pronounced tewple, "ew" as in new
@Itzcrystalroblox
@Itzcrystalroblox Жыл бұрын
i... understood nothing, maybe is my english problem
@bil4x467
@bil4x467 Жыл бұрын
Time hates semicolons :p
@LamYipMing
@LamYipMing Жыл бұрын
The way you miss semicolon every time you type is very irritating
@stuvius
@stuvius 9 ай бұрын
I also hate semicolons
@patricklittle1002
@patricklittle1002 Жыл бұрын
Lol about semicolons - the most normal muscle memory to do and he omits it
Rust Tutorial #5 - Console Input
8:56
Tech With Tim
Рет қаралды 70 М.
All Rust string types explained
22:13
Let's Get Rusty
Рет қаралды 168 М.
大家都拉出了什么#小丑 #shorts
00:35
好人小丑
Рет қаралды 81 МЛН
Oh No! My Doll Fell In The Dirt🤧💩
00:17
ToolTastic
Рет қаралды 13 МЛН
Люблю детей 💕💕💕🥰 #aminkavitaminka #aminokka #miminka #дети
00:24
Аминка Витаминка
Рет қаралды 1,3 МЛН
10 Important Python Concepts In 20 Minutes
18:49
Indently
Рет қаралды 90 М.
The Ultimate Tier Programming Tier List | Prime Reacts
26:57
ThePrimeTime
Рет қаралды 406 М.
10 Python Comprehensions You SHOULD Be Using
21:35
Tech With Tim
Рет қаралды 144 М.
rust runs on EVERYTHING (no operating system, just Rust)
18:10
Low Level Learning
Рет қаралды 356 М.
All Rust features explained
21:30
Let's Get Rusty
Рет қаралды 306 М.
Primitives Data Types In Java - All the Primitives And What They Do
10:24
C++ vs Rust: which is faster?
21:15
fasterthanlime
Рет қаралды 392 М.
Python 101: Learn the 5 Must-Know Concepts
20:00
Tech With Tim
Рет қаралды 1,1 МЛН
Rust's Most Important Containers 📦 10 Useful Patterns
17:11
Code to the Moon
Рет қаралды 121 М.
大家都拉出了什么#小丑 #shorts
00:35
好人小丑
Рет қаралды 81 МЛН