// Copyright (C) 2022 Marius Schellenberger

package fs

import (
	"sync"
)

type pool[T any] struct {
	p sync.Pool
}

func newPool[T any](newf func() T) *pool[T] {
	return &pool[T]{
		p: sync.Pool{
			New: func() any { return newf() },
		},
	}
}

func (p *pool[T]) Get() T {
	return p.p.Get().(T)
}

func (p *pool[T]) Put(v T) {
	p.p.Put(v)
}
