Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Clone Trait #141

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ That will look like:
```rust
impl<AccountId, Balance> Pallet<AccountId, Balance>
where
AccountId: Ord,
AccountId: Ord + Clone,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well noticed @0xScratch.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, thanks! 🚀

Balance: Zero + CheckedSub + CheckedAdd + Copy,
{
// functions which use these types and have access to the traits specified
Expand Down Expand Up @@ -133,7 +133,7 @@ pub struct Pallet {
/*
TODO:
The generic types need to satisfy certain traits in order to be used in the functions below.
- AccountId: Ord
- AccountId: Ord + Clone
- Balance: Zero + CheckedSub + CheckedAdd + Copy

You could figure these traits out yourself by letting the compiler tell you what you're missing.
Expand Down Expand Up @@ -195,4 +195,4 @@ pub struct Runtime {

Making the Balances Pallet generic is a crucial skill for creating flexible and scalable blockchain solutions. Great work on completing this lesson! 🌟

Post a screenshot in [#progress](https://discord.com/channels/898706705779687435/980906289968345128) showing your runtime with the new generic Balances Pallet in action. It better not still be using &'static str!
Post a screenshot in [#progress](https://discord.com/channels/898706705779687435/980906289968345128) showing your runtime with the new generic Balances Pallet in action. It better not still be using &'static str!
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The more obvious use of traits is to define custom functions

Let's say we want to expose a function which returns the name of something.

You could a trait `GetName`:
You could define a trait `GetName`:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌🏻


```rust
pub trait GetName {
Expand Down Expand Up @@ -82,7 +82,7 @@ For this we will use a trait with a bunch of associated types:

```rust
pub trait Config {
type AccountId: Ord;
type AccountId: Ord + Clone;
type BlockNumber: Zero + One + AddAssign + Copy;
type Nonce: Zero + One + Copy;
// and more if needed
Expand Down Expand Up @@ -159,7 +159,7 @@ Let's practice all you have learned to create `Config` trait for your System Pal
6. Go to your `main.rs` file, and implement `system::Config` for the `Runtime` struct.
7. Update your `Runtime` definition to instantiate `system::Pallet` with `Self`.

Again, this is a big step for new Rust developers, and a common place that people can get very confused.
Again, this is a big step for new Rust developers, and a commonplace where people can get very confused.

You will have the opportunity to do this whole process again for the Balances Pallet, so don't be afraid to peek at the solution this time around if you cannot get your code working.

Expand Down Expand Up @@ -233,4 +233,4 @@ mod test {
```

If you have any questions or need further assistance with implementing custom traits or configuring your System, feel free to reach out for support in the [#🆘・section-3](https://discord.com/channels/898706705779687435/980905695689998366) channel on Discord.
We're here to support you! 🌟
We're here to support you! 🌟