From the course: Rust for Data Engineering
Introduction to GitHub Copilot ecosystem for Rust - Rust Tutorial
From the course: Rust for Data Engineering
Introduction to GitHub Copilot ecosystem for Rust
- All right, let's go ahead and get started with what I think is one of the more exciting ways to be a software engineer, and this is to use Copilot inside of the GitHub ecosystem. So not just by itself, but with Visual Studio Code, with GitHub Codespaces, with GitHub. All those things together allows you to level up, right? In the old days when I first got started with Python, it was amazing, right? I got into Python and I was like, "Wow. You know, I can do all these things, script code quickly, move at the speed of light, it's amazing." That's really the same feeling when you level up to a more powerful language like Rust using Copilot. It's really that original Python experience, but the difference is, you have a modern language, a modern packaging system, you have 50 times better energy efficiency, you have 25 times at least better performance for computation, you have better, you know, memory usage because it's a very memory efficient language, and also in terms of security, right? You're building a very safe, concurrent, you know, build through the compiler, and also safe from a cybersecurity perspective. So there's all these awesome advantages. So really the question is, is it worth the penalty to use a slightly more complex language? With Copilot, it is, because you can use the existing knowledge you have as a Python programmer to apply that to Rust to level up your company. So I think this is going to be an emerging skill in 2023, and Python programmers don't have to throw away everything they learned. They can apply that with the techniques I'm about to show you. All right, let's go ahead and get started. All right, let's take a look here at a rust-new-project-template using the GitHub ecosystem. And really, this is the magic, right? This is why Copilot allows you to level up. You're existing Python programmer, you want to go to the next level, I would highly recommend GitHub Codespaces, plus Copilot, plus Visual Studio Code. This is the secret sauce, right? So if we go through here, we take a look at this, we have a Dockerfile that configures my environment with all the things I need. We also have inside of here devcontainer that configures features, for example, like Copilot. And in addition, what this means is that I can start this whenever I want with a new project, right? And so this is really the secret here, is I just say, "Hey, I'm going to go ahead and use this. I want to test my code automatically. Everything's is set up for me." Let's go ahead and use this template. Let's say Create a new repository. Go ahead and select the additional options here, and pick a nice powerful machine so I can compile my code. All right, so we're inside of this environment here. Let's just double check that everything works. One of the things that we can do is look at this Makefile here, which is a great idea to initially have in your project. If I type in make rust-version, what's nice about this is it tells me all of the nice things, you know, the version of Rust, all this stuff. And this comes for free, right? This is the big difference with Python. You don't have to do anything. It's just you're ready to go. So if I want to create a new project, what do I do? I just type in cargo new hello-marco. Right, let's go ahead and build a Marco Polo app. If I go through here, look at this. I have a packaging system all set up for me. So what I need to do here is inside put the dependencies that I care about. And so what I'm going to do is I'm going to go ahead and put a command line tool library here called clap, which is a very popular one. And then it's up to me to decide the structure. So if you're a Python programmer, I would recommend going through here and going to src and... Actually first cd into the directory, and then touch src and make a lib.rs. And this is where I like to put my logic. And here is where we also can build out some amazing things here by using Copilot. And this really is allowing us to leverage essentially our skills from Python. So we can first create a comment here that says, you know, a Marco Polo game. And then it's up to me to create the right prompt. So what I'm going to do is I'm going to say, you know, If the name Marco is given, the program will respond with Polo. Otherwise, we'll say, "What's your name?" Right? That looks pretty good, right? So it's just like a real person. We'll just need to prompt it correctly. And then I'm going to say as well some additional prompts here. And it's up to us, again, to really kind of guide it, right? So we want to do some stuff, here we go. And as long as you're helping it along the way, it's going to give you a good response. And in this case, we say, look, public, so expose this to my main module, which I'm going to use for command line tool, and then look at the rest. It's actually pretty intuitive. Look, we have a string here for the name. We do some stuff with a string and then we return a string, right? Very, very intuitive. Now, let's go to the main here. And the trick with this is, a lot of times all command line tool libraries are boilerplate code. And so what I'll do is, a lot of times if I'm building something, you know, I'll just cut and paste it from some other program to, again, help our prompt here. So I'm going to go ahead and just throw some stuff inside of here, you know, a command line tool to play Marco Polo, Marco Polo game. And this is all just boiler probably code. The big takeaway here is that you map a sub-command to the function that you've created inside of your lib. And this is almost identical to Python, except for, again, I get 25 times better performance, I can deploy binaries, all this other cool stuff. Once I've done this, I again can just look, okay, yeah, I want to pass a name into this. And then what'll happen is, I just ask Copilot to do the rest for me. And look, let's see what it does. It says, you know, eh, in this case, there's one thing it screwed up. We see that it's been able to generate a reasonable suggestion. That's not perfect, right? I want to tweak it a little bit. And so what I'm going to do is I'm going to, instead of letting it do the print name here, that's not exactly what I do, right? I want to send it Marco Polo. What I'm going to do is I'm going to say, instead, I'm going to tab and I'm going to say let result, and then I would guide it to the fact that I have a namespace in the module that I can use. And so this is one of the things that may trip you up a little bit when you're first using Rust is like, "Hey, wait, what is this, what is this?" You know, namespace is that, this, in fact, is what's inside of this Cargo file, right? It's this name. And so you have to actually map it to be the same name. Now again, what I could do here is I could just say make format, and just see what happens if I format my code. Does it clean it up a little bit? And what does this do? It says fail to use unresolved crate. Well, in this case, it is resolved because that's actually the name of the... Oh, actually the crate name is incorrect. The linter was telling me the right thing. So we have to change it to, in fact, hello_marco, right, we have to say hello_marco. How about that? There we go. Right, so this is where the analog tools, right, the Cargo system, as well as the Copilot work together, right, the formatter, linter, all this stuff works together, and then I just keep iterating to get the solution. Look, if the lint passes, we're in great shape. And now, I can use the final part, which is I can actually go through and run cargo to execute it. So this is a lot like running thing from the Python interpreter. All I have to do is type in cargo run --, and if we do the double dash right here, it passes in some command back into our program. And here we go. It's going to compile it now for the first time. And the Rust compiler is just amazing because it does all this really cool stuff to make your program safe and fast. We can see that it works. And now I can type in play and we can type in Marco, and this should return back, in fact, unexpected argument play because we need to do --name, right? There we go, Polo. And if I put in bob, right, it'll say, What's your name? Right, so this is a great feedback loop. And again, look at this target here. If I just go through here and I say /target/debug/ and I type in the hello-marco here, look at this, right? We see, in fact, I get that executable. So this is a huge win over regular Python in my opinion because of this fast feedback loop, the ability to use Copilot to level up and also to leverage this existing tool chain to have a feedback loop. So it's an emergent property of these new pair programming tools available from Copilot.
Contents
-
-
Meet the instructor and course overview7m 44s
-
Introduction to the AI coding paradigm shift3m 5s
-
Introduction to cloud-based development environments11m 24s
-
Introduction to GitHub Copilot ecosystem for Rust9m 13s
-
(Locked)
Prompt engineering with GCP BigQuery SQL9m 20s
-
(Locked)
Introduction to AWS CodeWhisperer for Rust7m 47s
-
(Locked)
Using Google Bard to enhance productivity6m 7s
-
(Locked)
Continuous integration with Rust and GitHub actions7m 52s
-
-
-
-
-
-
-
-
-
-
-
-