3 Jun 2024 |
| _desligado joined the room. | 17:56:12 |
| dekirisu joined the room. | 18:09:47 |
yuri@FreeBSD | How to fill datasets for the Chart object dynamically?
This code with static dataset elements (like in Ratatui examples) compiles fine:
let mut datasets = Vec::new();
for n in 1..10 {
let data = vec!((S + (n as f64), Y), (E + (n as f64), Y));
datasets.push(
Dataset::default()
.marker(Marker::Braille)
.style(Style::default().fg(Color::Red))
.graph_type(GraphType::Line)
.data(&[(1., 2.), (3., 4.)]));
}
let chart = Chart::new(datasets);
}
but a similar code with the dynamic array fails:
let mut datasets = Vec::new();
for n in 1..10 {
let data = vec!((S + (n as f64), Y), (E + (n as f64), Y));
datasets.push(
Dataset::default()
.marker(Marker::Braille)
.style(Style::default().fg(Color::Red))
.graph_type(GraphType::Line)
.data(&data)
);
}
let chart = Chart::new(datasets);
}
It fails like this:
53 | let data = vec!(((run.start as f32).into(), Y), ((run.end as f32).into(), Y));
| ---- binding `data` declared here
...
60 | .data(data.as_slice())
| ^^^^ borrowed value does not live long enough
...
63 | }
| - `data` dropped here while still borrowed
| 23:51:07 |
yuri@FreeBSD | * How to fill datasets for the Chart object dynamically?
This code with static dataset elements (like in Ratatui examples) compiles fine:
let mut datasets = Vec::new();
for n in 1..10 {
let data = vec!((S + (n as f64), Y), (E + (n as f64), Y));
datasets.push(
Dataset::default()
.marker(Marker::Braille)
.style(Style::default().fg(Color::Red))
.graph_type(GraphType::Line)
.data(&[(1., 2.), (3., 4.)])); // static array here
}
let chart = Chart::new(datasets);
}
but a similar code with the dynamic array fails:
let mut datasets = Vec::new();
for n in 1..10 {
let data = vec!((S + (n as f64), Y), (E + (n as f64), Y));
datasets.push(
Dataset::default()
.marker(Marker::Braille)
.style(Style::default().fg(Color::Red))
.graph_type(GraphType::Line)
.data(&data) // dynamic array here
);
}
let chart = Chart::new(datasets);
}
It fails like this:
53 | let data = vec!(((run.start as f32).into(), Y), ((run.end as f32).into(), Y));
| ---- binding `data` declared here
...
60 | .data(data.as_slice())
| ^^^^ borrowed value does not live long enough
...
63 | }
| - `data` dropped here while still borrowed
| 23:51:54 |
4 Jun 2024 |
yuri@FreeBSD | * How to fill datasets for the Chart object dynamically?
This code with static dataset elements (like in Ratatui examples) compiles fine:
pub fn xds(S: f64, E: f64, Y: f64, area: Rect, buf: &mut Buffer) {
let mut datasets = Vec::new();
for n in 1..10 {
let data = vec!((S + (n as f64), Y), (E + (n as f64), Y));
datasets.push(
Dataset::default()
.marker(Marker::Braille)
.style(Style::default().fg(Color::Red))
.graph_type(GraphType::Line)
.data(&[(1., 2.), (3., 4.)])); // static array here
}
let chart = Chart::new(datasets);
}
but a similar code with the dynamic array fails:
pub fn xds(S: f64, E: f64, Y: f64, area: Rect, buf: &mut Buffer) {
let mut datasets = Vec::new();
for n in 1..10 {
let data = vec!((S + (n as f64), Y), (E + (n as f64), Y));
datasets.push(
Dataset::default()
.marker(Marker::Braille)
.style(Style::default().fg(Color::Red))
.graph_type(GraphType::Line)
.data(&data) // dynamic array here
);
}
let chart = Chart::new(datasets);
}
It fails like this:
53 | let data = vec!(((run.start as f32).into(), Y), ((run.end as f32).into(), Y));
| ---- binding `data` declared here
...
60 | .data(data.as_slice())
| ^^^^ borrowed value does not live long enough
...
63 | }
| - `data` dropped here while still borrowed
| 01:37:49 |
7 Jun 2024 |
| @awiteb:4rs.nl joined the room. | 11:45:50 |
| @awiteb:4rs.nl left the room. | 11:51:06 |
| @awiteb:4rs.nl joined the room. | 11:51:21 |
| @awiteb:4rs.nl left the room. | 11:52:56 |
8 Jun 2024 |
| max_ishere changed their profile picture. | 10:12:18 |
11 Jun 2024 |
| Aziz Emir joined the room. | 16:51:35 |
19 Jun 2024 |
| Sam O’nella joined the room. | 05:39:48 |
21 Jun 2024 |
| @auronandace:matrix.org left the room. | 08:18:48 |
23 Jun 2024 |
| @joao00066joao:matrix.org joined the room. | 18:59:05 |
| @joao00066joao:matrix.org left the room. | 18:59:58 |
27 Jun 2024 |
| @alemi:alemi.dev left the room. | 16:19:47 |
29 Jun 2024 |
| Sam O’nella changed their display name from burntkrispe to BurntKrispe. | 05:28:40 |
30 Jun 2024 |
| Avery set a profile picture. | 00:06:06 |
| Avery changed their profile picture. | 00:07:44 |
| Avery set their display name to Avery. | 01:29:06 |
8 Jul 2024 |
| Sam O’nella changed their display name from BurntKrispe to Sam O’nella. | 04:55:28 |
| Sam O’nella changed their profile picture. | 16:45:13 |
10 Jul 2024 |
| @modev:bsd.cafe joined the room. | 14:58:54 |
11 Jul 2024 |
| @modev:bsd.cafe left the room. | 04:08:46 |
| Ninmi joined the room. | 21:49:55 |
12 Jul 2024 |
| yak0yakee0d joined the room. | 00:11:36 |
yak0yakee0d | Hi there! | 00:12:12 |
| @mur1chan:sakura.pm left the room. | 05:57:00 |
14 Jul 2024 |
stappers | Welcome | 18:43:30 |
19 Jul 2024 |
| Nico joined the room. | 10:49:28 |