Rust reborrow a mutable reference with a named lifetime

I’m new to rust and learning SDL2 at the same time (please forgive any errors and skipping of error handling). I’ve come across this scenario with mutable borrowing and named lifetimes, and after much googling I cannot find an answer.

In my code I’ve create a struct to be my SDL2 texture repository so that I can use them later. SDL2 and rust say that I need to give a named lifetime for the textures that I’m storing.

// Texture repository to create an store textures
pub struct TextureRepository<'a> {
  texture_creator: TextureCreator<WindowContext>,
  textures: Vec<Texture<'a>>
}
impl<'a> TextureRepository<'a> {
  pub fn new(texture_creator: TextureCreator<WindowContext>) -> Self {
    TextureRepository {
      texture_creator,
      textures: Vec::new()
    }
  }
  pub fn add_texture(&'a mut self, path: &str) {
    let texture = self.texture_creator.load_texture(path).unwrap();
    self.textures.push(texture);
  }
}

When I try to call the add_texture method from a mutable reference in a function, the compiler complains with:

error[E0499]: cannot borrow *texture_repository as mutable more than once at a time

fn main() {
  // Do SLD2 setup stuff here...
  // ...

  // Setup textures
  let texture_creator: TextureCreator<WindowContext> = canvas.texture_creator();
  let mut texture_repository: TextureRepository = TextureRepository::new(texture_creator);
  
  set_textures(&mut texture_repository);
}

fn set_textures<'a>(texture_repository: &'a mut TextureRepository<'a>) {
  texture_repository.add_texture("../../textures/character_1.png");
  texture_repository.add_texture("../../textures/character_2.png");
  // I get an error with this line above
}

If I call the add_texture method from the main function from the owning var instead, there are no problems:

fn main() {
  // Do SLD2 setup stuff here...
  // ...

  // Setup textures
  let texture_creator = canvas.texture_creator();
  let mut texture_repository = TextureRepository::new(texture_creator);
  
  texture_repository.add_texture("../../textures/character_1.png");
  texture_repository.add_texture("../../textures/character_2.png");
}

I don’t really want to be transferring around ownership to use the add_texture method unless I have to. And I want to keep my code structured and concise.

How can I make my set_textures function work? I’ve tried reborrowing and moving around into different scopes etc. But it just complains about the lifetime. It seems by using a named lifetime I can only mutably borrow once. From what I’ve read/understood: if I didn’t have to name the lifetime, then the second borrow would automatically become a different lifetime (compiler magic)??

How can I do this when you have to use a named lifetime?

FYI the struct for texture from the SDL2 lib looks like this

pub struct Texture<'r> {
    raw: *mut SDL_Texture,
    _marker: PhantomData<&()>,
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật