请大佬帮忙把一段之前golang实现的并发读写代码用rust实现
package main
import (
"fmt"
"sync"
"time"
)
type Rule struct {
Id int64
Words []string
}
type Repo struct {
Version int64
rwLock sync.RWMutex
Rules []*Rule
}
func main() {
r0 := Rule{
Id: 0,
Words: []string{"a", "b", "c"},
}
r1 := Rule{
Id: 1,
Words: []string{"0", "1", "2"},
}
repo := Repo{
Version: 0,
Rules: []*Rule{
&r0,
&r1,
},
}
var wg sync.WaitGroup
wg.Add(2)
go func() {
repo.rwLock.RLock()
rs := repo.Rules
repo.rwLock.RUnlock()
time.Sleep(2 * time.Second)
for i := range rs {
fmt.Println(rs[i].Id)
}
wg.Done()
}()
go func() {
time.Sleep(1 * time.Second)
repo.rwLock.Lock()
repo.Rules[1].Id = 999
repo.Rules = repo.Rules[0:1]
repo.Rules[0].Id = 1000
repo.rwLock.Unlock()
wg.Done()
}()
wg.Wait()
}