Boston Bruins general manager Don Sweeney dug in his heels and as a result, the Bruins signed David Pastrnak to a team-friendly contract extension. But in this case, it looks like everyone comes out a winner.

The B’s announced Thursday a six-year contract extension with the 21-year-old winger worth $40 million. Media and fans alike praised Sweeney for his ability to re-sign Pastrnak at such a manageable salary cap number, but Pastrnak certainly stands to benefit from the new pact, too.

The positives from the Bruins’ standpoint are obvious. They have a young forward, entering his fourth season in the NHL who appears well on his way to becoming an elite talent in the NHL. The 2014 first-round pick had easily the best season of his career in 2016-17 when Pastrnak scored 34 goals and added 36 assists in 75 games with the Bruins. From a points per game basis, only 14 players were more productive than Pastrnak last season, and he still has room to grow. He’s also a legitimate power-play weapon, as evidenced by the 14-10-24 totals on the man-advantage last season.

Locking up Pastrnak to a long-term deal also goes a long way in ensuring Boston’s core remains intact. The Bruins have Pastrnak’s potential linemates — Patrice Bergeron and Brad Marchand — signed through 2022 and 2025, respectively, and the new deal means Pastrnak will remain in Boston through the 2023 season. The NHL salary cap is set at $75 million for the upcoming season, which means the Bruins have only a quarter of their cap devoted to one of the best lines in the league.

The financial flexibility will continue to come in handy when other young B’s like Charlie McAvoy or Brandon Carlo come up for new contracts.

This is a good deal for Pastrnak, too. He’s now among the highest-paid right wingers in the NHL, and his AAV ($6.67 million per season) is consistent with other young forwards across the league. It’s also a tremendous opportunity for the young sniper. He’ll stay with a team in a market in which he’s clearly comfortable, and it actually might benefit Pastrnak that the deal isn’t a seven- or eight-year contract that had been circulating in reports.

Remember, Pastrnak is just 21 years old, meaning he’ll be an unrestricted free agent when he’s 27, right in the middle of his prime. Look at a player like Bobby Ryan, who as a 27-year-old right winger, signed a seven-year $50.75 million contract with Ottawa in 2014. Ryan has eclipsed the 70-point mark just once in his career. So not only does Pastrnak gets this $40 million now, setting him up for life, he puts himself in a position to really cash in down the line — assuming he continues to produce. That’s not bad considering Pastrnak, as a restricted free agent, wasn’t able to maximize his market. That will be a totally different story once he’s a UFA.

It’s not every day you can call a contract is a win-win for both the player and team, but it certainly seems, on the surface, the Bruins and Pastrnak were able to do just that.