You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: sampler_editor.rs
    path of file: ./repos/UnicornConsole/unicorn-editor/src/ui/audio/instrument_editor
    
    the code of the file until where you have to start completion: use eframe::{
    egui::{
        plot::{HLine, Line, Plot, PlotPoint, PlotPoints, VLine},
        Slider, Ui,
    },
    epaint::{Color32, Vec2},
};
use hound::WavReader;
use rfd::FileDialog;

use unicorn::audio::instruments::sampler::loop_mode::LoopMode;
use unicorn::audio::instruments::sampler::SampleBitDepth;
use unicorn::audio::instruments::sampler::sample_definition::SampleDefinition;


use crate::ui::AudioSyncHelper;

use super::envelope_widget::EnvelopeWidget;

#[derive(Default)]
pub struct SamplerEditor {
    points: Option<Vec<PlotPoint>>,
}

im
    
fn try_load_sample(instrument: &mut SampleDefinition) -> Result<(), &'static str> {
    if let Some(path) = FileDialog::new()
        .add_filter("wave (.wav)", &["wav"])
        .set_title("Load Sample")
        .pick_file()
    {
        let reader = WavReader::open(path).map_err(|_| "Failed to open file")?;

        // TODO: Handle Spec if things are the wrong setup
        let spec = reader.spec();
        let source_sample_rate = spec.sample_rate as usize;
        let data = reader
            .into_samples::<SampleBitDepth>()
            .flatten()
            .collect::<Vec<_>>()
            .into_boxed_slice();

        if data.is_empty() {
            return Err("Unable to convert sample into required i16 format.");
        }

        instrument.data = data;
        instrument.source_sample_rate = source_sample_rate;

        Ok(())
    } else {
        Err("User didn't pick a file")
    }
}